FizzBuzz.java 730B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Write a description of class FizzBuzz here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class FizzBuzz
  8. {
  9. // instance variables - replace the example below with your own
  10. private int x;
  11. /**
  12. * Constructor for objects of class FizzBuzz
  13. */
  14. public FizzBuzz()
  15. {
  16. // initialise instance variables
  17. }
  18. public String fizzbuzz(int y)
  19. {
  20. String result = "";
  21. if(y%3 == 0 && y%5 == 0){
  22. result = "FizzBuzz";}
  23. else if(y%3 == 0){
  24. result = "Fizz";}
  25. else if(y%5 == 0){
  26. result = "Buzz";
  27. }else {
  28. result = Integer.toString(y);}
  29. return result;
  30. }
  31. }