영상
문제
package 반복문2_문제;
/*
[문제]
10의 약수를 출력하시오.
[정답]
1, 2, 5, 10
*/
public class 반복문2_문제06_약수_문제 {
public static void main(String[] args) {
}
}
Java
복사
해설
package 반복문2_문제;
/*
[문제]
10의 약수를 출력하시오.
[정답]
1, 2, 5, 10
*/
public class 반복문2_문제06_약수_정답 {
public static void main(String[] args) {
int num = 10;
int i = 1;
while(i <= num) {
if(num % i == 0) {
System.out.print(i + " ");
}
i += 1;
}
}
}
Java
복사