Java
Java - while loop
CosmosProject
2021. 3. 11. 03:18
728x90
반응형
Original source = www.w3schools.com
While 반복문은 아래처럼 사용할 수 있습니다.
public class JavaWhileLoop {
public static void main(String args[]) {
int i = 0;
while (i <= 10) {
System.out.println(i);
i = i + 1;
}
}
}
-- Result
0
1
2
3
4
5
6
7
8
9
10
약간의 변형된 형태로 Do/While loop도 아래처럼 사용할 수 있습니다.
public class JavaWhileLoop {
public static void main(String args[]) {
int i = 0;
do {
System.out.println(i);
i = i + 1;
}
while (i <= 10);
}
}
-- Result
0
1
2
3
4
5
6
7
8
9
10
728x90
반응형