public class Sample5 {
    public static void main(String[] args) {
 
        int treeHit = 0;
        while (treeHit < 10){
            treeHit++;
            System.out.println("나무를  " + treeHit + "번 찍었습니다..");
            if (treeHit == 10) {
                System.out.println("나무 넘어갑니다.");
            }
        }
 
 

        /*while (true) {
            System.out.println("Ctrl-C를 눌러야 while문을 빠져 나갈 수 있습니다.");
        }  ====== 무한루프!
        */
 
 
 

        int coffee = 10;
        int money = 300;

        while (money>0) {
            System.out.println("돈을 받았으니 커피를 줍니다.");
            coffee --;
            System.out.println("남은 커피의 양은" + coffee + "입니다.");
            if (coffee == 0) {
                System.out.println("커피가 다 떨어졌습니다. 판매를 중지합니다.");
                break;
            }
        }
 
 
 
 

        int c = 0;
        while (c<=10) {
            c++;
            if (c%2==0){
                continue;
            }
            System.out.println(c);
            }
            //continue는 while의 맨 처음 조건문으로 돌아가게 해준다.
        }  
    }

'JAVA' 카테고리의 다른 글

[점프 투 자바] for each 문  (1) 2024.02.01
[점프 투 자바] for 문  (0) 2024.02.01
[점프 투 자바] switch, case문  (0) 2024.02.01
[점프 투 자바] if 문  (0) 2024.02.01
[점프 투 자바] 자료형 - 형 변환  (0) 2024.02.01

+ Recent posts