Print all numbers from 0 to 100
int num = 0;
while (num < 100) {
num++ ;
System.out.println(num);
}
Print numbers between 10 to 20
int num = 10;
do {
num++;
System.out.println(num);
} while (num < 20);
Add all numbers between 1 to 10
int num0 = 1, num1 = 0 ;
while(num0<=10) {
num1 += num0++;
}
System.out.println(num1);
}
Print only the even numbers between 1 and 10
int n = 0;
while (n < 10) {
n++;
if (n % 2 == 0)
System.out.println(n);
}
'java' 카테고리의 다른 글
Java/Break and Labeled break; (0) | 2020.01.27 |
---|---|
Java/Do-while loop (0) | 2020.01.25 |
Java/Def of MVC Pattern/Basic Address Management System (0) | 2020.01.25 |
자바의 연산자 (0) | 2020.01.25 |
자바의 강제형변환 (0) | 2020.01.25 |