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

Write a Java program that accepts a specified number of strings from the keyboar

ID: 3671488 • Letter: W

Question

Write a Java program that accepts a specified number of strings from the keyboard and stores them in an array. Start by asking the user how many strings they want to enter. Program should work for any reasonable number of strings. Create a String array of the specified size. Prompt the user to enter each string, read it from the keyboard, and store it in the array. Output the strings in the order entered. Then output the strings in the reverse order. Your outputs should match the sample run on the next slide.

Explanation / Answer

public class CharArrayPro
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("how many strings you want to enter?");
    int n= s.nextInt();
    String str[] = new String[n];
System.out.println("enter the strings");
    for(int i=0;i<n;i++)
    {
     str[i]=s.nextLine();
    }
System.out.println("the entered strings are");
for(int i=0;i<n;i++)
    {
       System.out.println(str[i]);
}
System.out.println("the entered strings in reverse order are");
for (int i = n-1; i >= 0 ; i--){
    System.out.print(str[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