백준 28702번(Java)

박은지·2025년 2월 4일

백준

목록 보기
14/89
post-thumbnail

import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		for(int i=3; i>0; i--) {
			String str = br.readLine();

			if(str.matches("^[0-9]*$")) {
				int n = Integer.parseInt(str) + i;
				
				if(n%3==0) {
					if(n%5==0) {
						// 3,5배수
						System.out.println("FizzBuzz");
						return;
					}
					// 3배수, 5배수X
					System.out.println("Fizz");
					return;
				} else if(n%5==0) {
					// 3배수X, 5배수
					System.out.println("Buzz");
					return;
				} else {
					// 3,5배수 X
					System.out.println(n);
					return;
				}
			}
		}
		
		br.close();
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글