Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 list=new ArrayList(); Scanner scan =new Scanner(System.in); System.out.println("Please enter words, enter STOP to stop the loop."); String input = scan.nextLine(); while(!input.equals("STOP")) { list.add(input); input=scan.nextLine(); } System.out.println(list); for(int i = list.size()-1; i>= 0; i--){ System.out.print(list.get(i)); for(int b = 0; b < list.size(); b++){ System.out.print(list.get(b)); System.out.println(); } }

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions