for (변수의 초기화; 탈출조건식; 증감식) {
탈출 조건식이 참인 경우 실행되는 부분
}
public class ForExam1 {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println("*");
}
}
}
*
*
*
*
*
*
*
*
*
*
public class ForExam2 {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
System.out.println(i);
}
}
}
1
2
3
4
5
6
7
8
9
10
public class StringExam1 {
public static void main(String[] args) {
String str1 = "hello" + 1;
String str2 = "hello" + true;
String str3 = "hello" + 50.4;
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
}
}
hello1
hellotrue
hello50.4
public class Gugudan1 {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
System.out.println("1 * " + i + " = " + (1 * i));
}
}
}
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
public class Gugudan2 {
public static void main(String[] args) {
for (int k = 1; k <= 9; k++) {
for (int i = 1; i <= 9; i++) {
System.out.println(k + "*" + i + "=" + (k * i));
}
}
}
}
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
...
9 * 9 = 81