Question
Write a Java program that allows a user to input multiple words. Your program should stop accepting words when the user enters STOP. Store the
Write a Java program that allows a user to input multiple words. Your program should stop accepting words when the user enters "STOP". Store the words in an ArrayList. The word STOP should not be stored in the list.
Next, print the ArrayList, then print all the strings from this list in the reverse order to which they appear in the list, with each one on a new line, while adding the strings from the array in sequential order starting from the beginning.
Sample Run:
Please enter words, enter STOP to stop the loop. winter fall spring summer STOP
[winter,fall,spring,summer] summerwinter springfall fallspring wintersummer Note: For this activity, you must use the class name, U7_L2_Activity_One and the method, main.
Hint: printing the entire ArrayList needs only one statement, however to print each String from the list individually on a new line starting from the last value, you will need to write a loop which starts at the end of the list and works backwards through it.
Here is my code:
import java.util.Scanner; import java.util.ArrayList;
public class U7_L2_Activity_One {
public static void main(String[] args) { /* write your code here */ ArrayList
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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