문법
1 2 3 4 | while(조건식) { // 조건식의 연산결과가 true 일 때 수행될 문장 } | cs |
예제
1 2 3 4 5 6 7 8 9 | public class WhileTest_01 { public static void main(String[] args) { int i =10; while(i>0) System.out.println(i--); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // while 이용 구구단 public class WhileTest_02 { public static void main(String[] args) { int i=2; while(i<=9) { int j=1; while(j<=9) { System.out.println(i+" * "+j+" = "+i*j); j++; } i++; } // end while(i<=9) } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class WhileTest_02 { public static void main(String[] args) { int sum = 0; int i=0; while(sum+i<=100) { sum += i++; System.out.println(i+" - " +sum); } } } | cs |