영상
문제
package 반복문1_문제;
/*
[문제]
1~5까지의 합을 출력하시오.
1 + 2 + 3 + 4 + 5
[정답]
15
*/
public class 반복문1_문제05_기본문제_문제 {
public static void main(String[] args) {
}
}
Java
복사
해설
package 반복문1_문제;
/*
[문제]
1~5까지의 합을 출력하시오.
1 + 2 + 3 + 4 + 5
[정답]
15
*/
public class 반복문1_문제05_기본문제_정답 {
public static void main(String[] args) {
int total = 0;
int i = 1;
while(i <= 5) {
total += i;
i += 1;
}
System.out.println(total);
}
}
Java
복사