1부터 주어진 숫자만큼 모두 더한 값을 출력하시오.
단, 주어질 숫자는 10000을 넘지 않는다.
[예제]
주어진 숫자가 10 일 경우 출력해야 할 정답은,
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
import java.io.*;
class Solution {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
int answer = 0;
for(int i = 1 ; i <= num ; i ++)
answer += i;
System.out.print(answer);
}
}
'코딩테스트 > SWEA' 카테고리의 다른 글
[SWEA] (D1) 2043. 서랍의 비밀번호 (0) | 2024.10.13 |
---|---|
[SWEA] (D1) 2058. 자릿수 더하기 (1) | 2024.10.13 |
[SWEA] (D1) 2047. 신문 헤드라인 (1) | 2024.10.13 |
[SWEA] (D1) 2046. 스탬프 찍기 (0) | 2024.10.13 |
[SWEA] (D1) 1938. 아주 간단한 계산기 (0) | 2024.10.13 |