Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /*
  2. * Write a program that outputs the string
  3. * representation of numbers from 1 to n.
  4. * But for multiples of three it should output “Fizz”
  5. * instead of the number and for the multiples of five output “Buzz”.
  6. * For numbers which are multiples of both three and five output “FizzBuzz”.
  7. */
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. public class FizzBuzz {
  13.  
  14. private static List<String> list = new ArrayList<String>();
  15. private static String numString = "";
  16. private static int count = 0;
  17.  
  18. public static List<String> fizzBuzz(int n) {
  19.  
  20. for (int i = 0; i < n; i++) {
  21. numString = String.valueOf(n);
  22. list.add(numString);
  23. n--;
  24. }
  25.  
  26. list.add("one");
  27. list.add("two");
  28.  
  29. return list;
  30.  
  31. }
  32.  
  33. public static void main (String[] args) {
  34. System.out.println(list);
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement