Interview Replay

Question 1

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

package com.rocketpush.puzzle;

public class FizzBuzz {

    public static String fizzBuzz (boolean isFizzy, boolean isBuzzy, int i) {
        String value = String.valueOf(i);
        if (isFizzy && isBuzzy) {
            value = "FizzBuzz";
        } else if (isFizzy) {
            value = "Fizz";
        } else if (isBuzzy) {
            value = "Buzz";
        }
        
        return value;
    }

    public static void main (String... args) {
        for (int i = 1; i <= 100; i += 1) {
            boolean isFizzy = i % 3 == 0;
            boolean isBuzzy = i % 5 == 0;
            String result = fizzBuzz(isFizzy, isBuzzy, i);
            System.out.println(result);
        }
    }
}
0:00 / 4:44