PS/BOJ

백준 5341 Pyramids / JAVA

얍연구소장 2023. 4. 12.

https://www.acmicpc.net/problem/5341

 

5341번: Pyramids

The input will be a sequence of integers, one per line. The end of input will be signaled by the integer 0, and does not represent the base of a pyramid. All integers, other than the last (zero), are positive.

www.acmicpc.net

 

> 풀이

 

import java.util.Scanner;

/*
 * 백준 5341 Pyramids
 * #브론즈5
 */
public class boj_5341 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int result = 0;
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int n = sc.nextInt();
			if(n == 0) {
				System.exit(0);
			}
			
			result = solution(n);
			System.out.println(result);
		}
		
	}
	
	public static int solution(int n) {
		return n * (n+1) / 2; // 등차수열의 합
	}
}

'PS > BOJ' 카테고리의 다른 글

백준 9465 스티커 / JAVA  (0) 2023.04.17
백준 1251 단어 나누기 / JAVA  (0) 2023.04.14
백준 2037 문자메시지 / JAVA  (0) 2023.04.11
백준 1952 달팽이2 / JAVA  (0) 2023.04.09
백준 1524 세준세비 / JAVA  (0) 2023.04.05

댓글