Write with Java arrays a program that does the following

Write with Java ( arrays ) a program that does the following:

• Asks the user to specify the number of names he/she wants to input.

• Accordingly, declare an array of appropriate size.

• Accept the required number of names from the user.

• Store these names received from the user in a String array.

• Print the names to the screen in uppercase.

Solution

Strings.java

import java.util.Scanner;


public class Strings {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.print(\"Enter the number of names: \");
       int n = scan.nextInt();
       scan.nextLine();
       String names[] = new String[n];
       for(int i=0; i<names.length; i++){
           System.out.print(\"Enter name: \");
           names[i] = scan.nextLine();
       }
       System.out.println(\"Given names in uppercase: \");
       for(int i=0; i<names.length; i++){
           System.out.println(names[i].toUpperCase());
       }

   }

}

Output:

Enter the number of names: 4
Enter name: Suresh Murapaka
Enter name: Sekhar Murapaka
Enter name: Anshu Murapaka
Enter name: Revathi Murapaka
Given names in uppercase:
SURESH MURAPAKA
SEKHAR MURAPAKA
ANSHU MURAPAKA
REVATHI MURAPAKA

Write with Java ( arrays ) a program that does the following: • Asks the user to specify the number of names he/she wants to input. • Accordingly, declare an ar

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site