asked 148k views
0 votes
2) Write a Java application that stores the names of your family and friends in a one-dimensional array of Strings. The program should show all names in upper case and lower case, identify the first character of the name, and the lengths of the names.

1 Answer

3 votes

Answer:

Here's an example Java application that stores the names of family and friends in a one-dimensional array of Strings and performs the requested operations:

public class NameArrayDemo {

public static void main(String[] args) {

// Define the array of names

String[] names = {"Alice", "Bob", "Charlie", "David", "Emily", "Frank"};

// Loop through the array and display each name in upper case

System.out.println("Names in upper case:");

for (String name : names) {

System.out.println(name.toUpperCase());

}

// Loop through the array and display each name in lower case

System.out.println("\\Names in lower case:");

for (String name : names) {

System.out.println(name.toLowerCase());

}

// Loop through the array and display the first character of each name

System.out.println("\\First character of each name:");

for (String name : names) {

System.out.println(name.charAt(0));

}

// Loop through the array and display the length of each name

System.out.println("\\Length of each name:");

for (String name : names) {

System.out.println(name.length());

}

}

}

When you run this program, it should output the following:

Names in upper case:

ALICE

BOB

CHARLIE

DAVID

EMILY

FRANK

Names in lower case:

alice

bob

charlie

david

emily

frank

First character of each name:

A

B

C

D

E

F

Length of each name:

5

3

7

5

5

5

I hope this helps!

Step-by-step explanation:

answered
User Demokritos
by
8.5k points