ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [JAVA] while 반복문
    JAVA 2023. 7. 11. 21:51
    while 반복문
    /*while문 예시*/
    public class Test {
        public static void main(String[] args) throws Exception {
            int num = 0;
    
            while (num < 10){
                System.err.println(num);
                num += 1;
            }
        }
    }
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9

     

    do - while 반복문
    /*while문 예시*/
    public class Test {
        public static void main(String[] args) throws Exception {
            /*while문*/
            int cnt1 = 0;
            while (cnt1 < 5){
                System.err.println(cnt1);
                cnt1 += 1;
            }
    
            /*do-while문*/
            int cnt2 = 0;
            do{
                System.err.println(cnt2);
                cnt2 ++;
            }while(cnt2 <5);
        }
    }
    0
    1
    2
    3
    4
    0
    1
    2
    3
    4

    'JAVA' 카테고리의 다른 글

    [JAVA] 메소드 호출문  (0) 2023.07.13
    [JAVA] for 반복문  (0) 2023.07.11
    [JAVA] 조건문  (0) 2023.07.11
    [JAVA] 배열  (0) 2023.07.10
    [JAVA] 로컬 변수의 사용 방법  (0) 2023.07.10
Designed by Tistory.