Algorithm/백준
[백준] 8393: 합 - JAVA [자바]
이민균
2023. 4. 18. 14:38

문제

문제 풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
int result = 0;
for (int i = 0; i <= number; i++) {
result += i;
//(1)
}
System.out.println(result);
//(2)
}
}
- 수를 입력받아 1부터 입력한 수 까지 1씩 result에 더해줍니다.
- result를 출력합니다
결과
