Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Write a program that outputs the string
- * representation of numbers from 1 to n.
- * But for multiples of three it should output “Fizz”
- * instead of the number and for the multiples of five output “Buzz”.
- * For numbers which are multiples of both three and five output “FizzBuzz”.
- */
- import java.util.ArrayList;
- import java.util.List;
- public class FizzBuzz {
- private static List<String> list = new ArrayList<String>();
- private static String numString = "";
- private static int count = 0;
- public static List<String> fizzBuzz(int n) {
- for (int i = 0; i < n; i++) {
- numString = String.valueOf(n);
- list.add(numString);
- n--;
- }
- list.add("one");
- list.add("two");
- return list;
- }
- public static void main (String[] args) {
- System.out.println(list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement