SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
24.
구구단 완성
public class Gugudan {
public static void main(String[] args) {
for (int i = 2; i <= 9; i = i + 1) {
for (int j = 1; j <= 9; j = j + 1) {
int k = i * j;
System.out.println( i + " * " + j + " = " + k);
}
}
}
}
31.
메소드 (method)
package simple;
public class Gugudan {
public static void main(String[] args) {
for (int i = 2; i <= 9; i = i + 1) {
printDan(i);
}
}
...
32.
메소드(method)
...
public static void printDan(int i) {
for (int j = 1; j <= 9; j = j + 1) {
int k = i * j;
System.out.println( i + " * " + j + " = " + k);
}
}
} // class end
33.
메소드 Outline
package simple;
public class Gugudan {
public static void main(String[] args) {...}
public static void printDan(int i) {...}
}
34.
메소드 signature
•public static void main(String[] args)
•public: 접근자 private, protected
•static: 메모리 점유 (optional)
•void: return type 없음
•main: 메소드 이름
•String[] args: 파라미터
35.
Bonus
public static void main(String[] args) {
System.out.println("gugudan from:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
for (; i <= 9; i = i + 1) {
printDan(i);
}
}
36.
이용하자
자바 라이브러리 jar
•클래스 모음
•jar: Java ARchive(기록 보관)
•zip 알고리즘
•tar와 유사 (Tape ARchive)
37.
jar 만들기
•jar cvf gugudan.jar *
•jar xvf: 풀기
•jar tvf: 목록 보기
•META-INF/MANIFEST.MF
•jar 파일의 버전 등의 정보
•실행 클래스 설정
•제외 옵션: cvfM