← Back to List

14761번: FizzBuzz ↗

Solutions

Java 8
626 B | 626 chars
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int Y= sc.nextInt();
        int N = sc.nextInt();
        for(int x=1; x<=N; x++) {
            boolean c = false;
            if(x%X == 0) {
                System.out.print("Fizz");
                c = true;
            }
            if(x%Y == 0) {
                System.out.print("Buzz");
                c = true;
            }
            if(!c) {
                System.out.print(x);
            }
            System.out.println();
        }
    }
}