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++;
}
}
}
while 반복문
2024. 1. 26. 16:19