Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please see below help would be appreciated thank you! Intro to JAVA Programming

ID: 3700843 • Letter: P

Question

Please see below help would be appreciated thank you! Intro to JAVA Programming

________________________________________________________________________________________________________________________________

Write a program that reads in words and prints them out in reverse order. Complete this code.

import java.util.ArrayList;
import java.util.Scanner;

public class ReverseInput
{
   public static void main(String[] args)
   {
      ArrayList<String> words = new ArrayList<String>();

      Scanner in = new Scanner(System.in);    
      // Read input into words
      while (in.hasNext())
      {
         . . .
      }

      // Reverse input
      for (. . .)
      {
         System.out.print(words.get(i) + " ");
      }
   }
}

Explanation / Answer

ReverseInput.java

import java.util.ArrayList;

import java.util.Scanner;

public class ReverseInput {

public static void main(String[] args) {

ArrayList<String> words = new ArrayList<String>();

Scanner in = new Scanner(System.in);

while(in.hasNext()){

words.add(in.next());

}

for(int i=words.size()-1; i>=0; i--){

System.out.print(words.get(i)+" ");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote