본문으로 바로가기

자바 반복문 - do-while문

category 코딩/Java 2016. 9. 3. 08:00





문법


1
2
3
4
do
{
    // 조건식의 연산결과가 true일 때 수행될 문장
while(조건식);
cs




예제


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.io.IOException;
 
//do-while 문
public class DoWhileTest_01
{
    public static void main(String[] args)
    {
        int input=0;
        System.out.println("문장입력");
        System.out.println("입력을 마치려면 x를 입력하세요");
        
        try 
        {
            do
            {
                input = System.in.read();
                System.out.println((char)input);
            }
            while(input !=-1 && input !='x');
            
        } catch (IOException e) {
            System.out.println("IOException 발생");
            e.printStackTrace();
        }
    }
}
cs





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

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