영상
문제
package 반복문1_문제;
/*
[문제]
1~10까지 반복문을 실행하고
3의 배수의 개수를 출력하시오.
[정답]
3
*/
public class 반복문1_문제06_기본문제_문제 {
public static void main(String[] args) {
}
}
Java
복사
해설
package 반복문1_문제;
/*
[문제]
1~10까지 반복문을 실행하고
3의 배수의 개수를 출력하시오.
[정답]
3
*/
public class 반복문1_문제06_기본문제_정답 {
public static void main(String[] args) {
int count = 0;
int i = 1;
while(i <= 10) {
if(i % 3 == 0) {
count += 1;
}
i += 1;
}
System.out.println(count);
}
}
Java
복사