Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

Everything has an expiration date

BAEKJOON - 8393 : 합 본문

BAEKJOON - challenge/반복문

BAEKJOON - 8393 : 합

Jelly-fish 2023. 9. 17. 21:21

import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		// 1. 변수 선언
		Scanner sc = new Scanner(System.in);
		int n;
		int sum = 0;
		
		// 2. 사용자로부터 1부터 n까지의 합을 구할 수 n을 입력받는다.
		n = sc.nextInt();
		
		// 3. 반복문을 돌면서 1부터 n까지의 합을 구한 후, 출력한다.
		for (int i = 1; i <= n; i++)
		{
			sum += i;
		}
		
		System.out.println(sum);
		
	}

}

🍠🥪