Question
What are some of the other ways that I can print the ArrayList fizzBuzzList out? import java.util.*; public class Main { List fizzBuzzList = new
What are some of the other ways that I can print the ArrayList fizzBuzzList out?
import java.util.*;
public class Main {
List
public void fizzBuzzIterator(){
for (int i = 1; i <= 100; i++) { //fizzBuzzList.add("0");
if (((i % 3) == 0) && ((i % 5) == 0)) {
fizzBuzzList.add(i-1, "FizzBuzz");
}
else if ((i % 3) == 0){
fizzBuzzList.add(i-1, "Fizz");
}
else if ((i % 5) == 0) {
fizzBuzzList.add(i-1, "Buzz");
}
else {
fizzBuzzList.add(i-1, String.valueOf(i));
}
}
}
public static void main(String[] args){ Main m = new Main(); m.fizzBuzzIterator(); for(int k = 0; k < m.fizzBuzzList.size(); k++){
System.out.println(m.fizzBuzzList.get(k));
}
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started