Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!