백준 알고리즘
3. 반복문 - 3 (8393번)
IT의 큰손
2023. 2. 28. 11:15
728x90
★ 문제
- n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.
★ 소스코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int result = 0;
for(int i=1; i<=n; i++) {
result += i;
}
System.out.println(result);
}
}
728x90