package com.study.javastudy.study;

public class WhileExam {
    public static void main(String[] args) {
        int i = 0;

        while (i<10) {
            System.out.println(i); //이것만 출력하면 i가 무한으로 출력됨
            i++; // i = i + 1; 0 ~ 9까지 출력됨
        }

        int total = 0;
        int i1 = 1;
        while (i1<=100) {
            total = total + i1;
            i1++; // i1 = i1 + 1
        }
        System.out.println(total); // 5050

//        while(true) {
//            System.out.println("hello"); // 문자도 계속 출력됨
//        }

        int i2 = 1;
        while(i2 < 11){
            // if 문을 추가해, i가 짝수일때만 i를 출력하게 할 수 있다.
            if(i2 % 2 == 0)
                System.out.println(i2);
            i2++;
        }
    }
}

'자바 기초' 카테고리의 다른 글

for문  (0) 2024.01.27
do while문  (0) 2024.01.26
switch 조건문  (0) 2024.01.26
삼항연산자  (0) 2024.01.26
논리 연산자  (0) 2024.01.26

+ Recent posts