์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step3] 8393 : ํ•ฉ (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 6. 18:22

www.acmicpc.net/problem/8393

 

8393๋ฒˆ: ํ•ฉ

n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ n๊นŒ์ง€ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net


๋ฌธ์ œ

n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ n๊นŒ์ง€ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— n (1 ≤ n ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค.

 

์ถœ๋ ฅ

1๋ถ€ํ„ฐ n๊นŒ์ง€ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

3

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

6


ํ’€์ด

 

import java.util.Scanner;

public class B8393 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int total = 0;
		
		for(int i = 1; i < n+1; i++) {
			total += i;
		}
		
		System.out.println(total);

	}

}