Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, 3 things need to be changed 1. Array size should be less than 100 2. in the input, first enter the name. when

In Java,

3 things need to be changed

1. Array size should be less than 100

2. in the input, first enter the name. when entering the "END", the program ends the first loop, and then you can enter the Gifts. After entering a few gifts, enter "END" again. the program should end and print the NAMES, GIFTS as sort.

3. When printing the output, should only print the name, gift. when they do not have the same first letter, only print the name. In the end, print all gifts which not show before.

Scanner sc = new Scanner(System.in); int totalNames = 100; int totalGifts = 100; String[] Names = new String [totalNames]; // Array for names String[] Gifts = new String [totalGifts]; // Array for gifts //while (!sc.equals("END")) { for(int o = 0; o < Names.length;o++) // for loop for input the Names { System.out.print("Enter the Names:"); Names[o] = sc.nextLine(); //break; } // } // while(sc.equals("END"));{ for(int p = 0; p < Gifts.length;p++) // for loop for input the Gifts { System.out.print("Enter the gifts:"); Gifts[p] = sc.nextLine(); //break; } // } int num = Names.length; for(int j=1; j 0 && Names[i-1].compareTo(t) > 0) { Names[i] = Names[i-1]; i--; } Names[i] = t; } System.out.println("*END*"); for(String s : Names) // print as sort when name first letter == gifts first letter { for (String g : Gifts) { if (s.charAt(0)==g.charAt(0)) { System.out.print(s +", " + g); System.out.println(); } else{ System.out.print(""); } } } System.out.println("*END*"); // end

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago