FizzBuzz.java 316B

123456789101112131415161718
  1. public class FizzBuzz{
  2. public String fizzBuzz(int num){
  3. if (num % 3 == 0 && num % 5 == 0) {
  4. return "fizzbuzz";
  5. }
  6. if (num % 3 == 0) {
  7. return "fizz";
  8. }
  9. else if (num % 5 == 0) {
  10. return "buzz";
  11. }
  12. return "" + num;
  13. }
  14. }