-
[브론즈 Ⅴ] 5341번 :: Pyramids / Java백준/브론즈 2023. 2. 21. 18:42
문제
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; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); while(true) { int n = scan.nextInt(); int block = 0; if(n==0) break; block = pyramid(n); System.out.println(block); } scan.close(); } public static int pyramid(int num) { if(num == 1) return 1; return pyramid(num-1) + num; } }
'백준 > 브론즈' 카테고리의 다른 글
[브론즈 Ⅴ] 5597번 :: 과제 안 내신 분..? / Java (0) 2023.02.21 [브론즈 Ⅴ] 6840번 :: Who is in the middle? / Java (0) 2023.02.21 [브론즈 Ⅴ] 4999번 :: 아! / Java (0) 2023.02.21 [브론즈 Ⅴ] 4101번 :: 크냐? / Java (0) 2023.02.21 [브론즈 Ⅴ] 3733번 :: Shares / Java (0) 2023.02.21