본문으로 바로가기

자바 반복문 - while문

category 코딩/Java 2016. 9. 2. 12:30




문법


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


'코딩 > Java' 카테고리의 다른 글

자바 break문  (0) 2016.09.03
자바 반복문 - do-while문  (0) 2016.09.03
자바 반복문 - for문  (0) 2016.09.02
자바 조건문 - switch문  (0) 2016.08.31
자바 조건문 - if문  (0) 2016.08.31
RSS구독 링크추가 트위터 이메일 구독