FizzBuzz.java 798B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. String start = "";
  10. /**
  11. * An example of a method - replace this comment with your own
  12. *
  13. * @param y a sample parameter for a method
  14. * @return the sum of x and y
  15. */
  16. public String printLine(int number)
  17. {
  18. for(int x = 1; x <= number; x++){
  19. start += x + " ";
  20. }
  21. return start;
  22. }
  23. public String printFizzBuzz(int number){
  24. for(int x = 1; x <= number; x++){
  25. if(x % 15 ==0)
  26. start +="FizzBuzz ";
  27. else if (x % 3 ==0)
  28. start +="Fizz ";
  29. else if (x % 5 ==0)
  30. start +="Buzz ";
  31. else
  32. start += x + " ";
  33. }
  34. return start;
  35. }
  36. }