코이팅

[백준 JAVA] 8393번 : 합 본문

백준 알고리즘/Bronze

[백준 JAVA] 8393번 : 합

코이팅 2022. 11. 22. 11:43
728x90
반응형

[Bronze V] 합 - 8393

문제 링크

성능 요약

메모리: 17616 KB, 시간: 204 ms

분류

구현(implementation), 수학(math)

문제 설명

n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 n (1 ≤ n ≤ 10,000)이 주어진다.

출력

1부터 n까지 합을 출력한다.

 

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int num = stdIn.nextInt();
        int total = 0;

        for (int i = 1; i <= num; i++) {
            total += i;
        }

        System.out.println(total);
    }
}
728x90
반응형
Comments