FizzBuzz.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import java.util.*;
  2. /**
  3. * Write a description of class FizzBuzz here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class FizzBuzz
  9. {
  10. // instance variables - replace the example below with your own
  11. private int x;
  12. /**
  13. * Constructor for objects of class FizzBuzz
  14. */
  15. public FizzBuzz()
  16. {
  17. // initialise instance variables
  18. x = 0;
  19. }
  20. /**
  21. * An example of a method - replace this comment with your own
  22. *
  23. * @param y a sample parameter for a method
  24. * @return the sum of x and y
  25. */
  26. public static String FizzBuzzGame(int number)
  27. {
  28. Scanner sc = new Scanner(System.in);
  29. number = sc.nextInt();
  30. if(number % 3 == 0 && number % 5 == 0){
  31. System.out.println("FizzBuzz");
  32. return "FizzBuzz";
  33. } else if(number % 3 == 0){
  34. System.out.println("Fizz");
  35. return "Fizz";
  36. } else if (number % 5 == 0){
  37. System.out.println("Buzz");
  38. return "Buzz";
  39. }
  40. return "Thank for playing";
  41. }
  42. }