영상
문제
package 반복문2_문제;
/*
[문제]
8의 배수를 8부터 순차적으로 4개만 출력하시오.
[정답]
8, 16, 24, 32
*/
public class 반복문2_문제02_배수_문제 {
public static void main(String[] args) {
}
}
Java
복사
해설
package 반복문2_문제;
/*
[문제]
8의 배수를 8부터 순차적으로 4개만 출력하시오.
[정답]
8, 16, 24, 32
*/
public class 반복문2_문제02_배수_정답 {
public static void main(String[] args) {
int i = 1;
int count = 0;
boolean run = true;
while(run) {
if(i % 8 == 0) {
System.out.print(i + " ");
count += 1;
if(count == 4) {
run = false;
}
}
i += 1;
}
}
}
Java
복사