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);
}
}