gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
write a for loop in java which prints a list of questions
- User
write a for loop in java which prints a list of questions
- Assistant
Sure! Here's an example of a for loop in Java that prints a list of questions:
javaimport java.util.ArrayList; public class QuestionList { public static void main(String[] args) { // Create a list of questions ArrayList<String> questions = new ArrayList<>(); questions.add("What is your name?"); questions.add("How old are you?"); questions.add("Where are you from?"); questions.add("What is your favorite color?"); // Loop through the list and print each question for (String question : questions) { System.out.println(question); } } }This program creates an
ArrayListcalledquestionsand adds some questions to it. Then, it uses a for-each loop to iterate through the list and print each question using theSystem.out.println()method.