Skip to main content
1 of 4
K.H.
  • 2.7k
  • 7
  • 25

If simplification

First if can be simplified to input % 15. Basically you are checking for number divisible by 3 and 5, so you can just check for 15. I agree with using brackets even here as mentioned by @Captain Man

public String pickOne(int input) {

    if ((input % 15) == 0) {
        return "fizzbuzz";
    } else if ((input % 3) == 0) {
        return "fizz";
    } else if((input % 5) == 0) {
        return "buzz";
    }

    return String.valueOf(input);
} 
K.H.
  • 2.7k
  • 7
  • 25