fizzbuzz program code example
Example 1: fizzbuzz java
public static String fizzBuzz(int number) {
if (number % 3 == 0) {
if (number % 5 == 0) {
return "fizzbuzz";
} else {
return "fizz";
}
} else if (number % 5 == 0) {
return "buzz";
}
return String.valueOf(number);
}
Example 2: FizzBuzz
for (let i = 1, msg; i <= 100; i++, msg = '') {
if (!(i % 3)) msg += 'Fizz';
if (!(i % 5)) msg += 'Buzz';
console.log(msg || i);
}