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

Wirte a program that accepts 10 words from the user. Store these words in an arr

ID: 3538855 • Letter: W

Question

Wirte a program that accepts 10 words from the user. Store these words in an array or an arrayList.

Display the following to the user:

1) Loop through the array or arrayList and display the words in reverse order.
2) Display the 5th word entered by the user.
3) Display the 1st word entered by the user.


import java.util.Scanner;

public class Arraylist {


public static void main(String[] args)
{
Scanner X = new Scanner(System.in);
String[] array = new String[10];

String k = " ";
for(int j = 0; j < 10; j++)
{
System.out.println("Enter Word");
k = X.nextLine();
array[j] = k;
}

System.out.println("Part 1");

String dummy = " ";
for(int i = 10; i > 0; i--)
{
dummy = array[i];
System.out.println(" "+dummy);
}

System.out.println("Part 2");

String d2 = array[4];
System.out.println(" "+d2);

System.out.println("Part 3");

d2 = array[0];
System.out.println(" "+d2);
}
}


Part one isn't working need help!

Explanation / Answer

//CORRECTED PROGRAM import java.util.Scanner; class Arraylist { public static void main(String[] args) { Scanner X = new Scanner(System.in); String[] array = new String[10]; String k = " "; for(int j = 0; j < 10; j++) { System.out.println("Enter Word"); k = X.nextLine(); array[j] = k; } System.out.println("Part 1"); String dummy = " "; //you should start from index i=9, and go upto and equal to 0. for(int=9;>=0;--){=[];Systemoutprintln(" "+);}Systemoutprintln("Part 2");String=[4];Systemoutprintln(" "+);Systemoutprintln("Part 3");=[0];Systemoutprintln(" "+);}}
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