Home > Back-end >  Mainly is the last request!
Mainly is the last request!

Time:10-18

Keyboard input the number of students, and then repeated input more than one student's name, put all the student information saved in the array, cannot duplicate entry student's name, otherwise an error and required to input, in addition, statistical different last name, and the output,

CodePudding user response:

Arrays are allowed to repeat itself! You are the all data structure called an array?

Statistics of this problem, is not difficult to give you an example:

 
Public class StreamTest {
Private final Stream The menu=Arrays. AsList (
New Dish (" pork ", false, 800, Dish. The MEAT),
New Dish (" beef ", false, 700, Dish. The MEAT),
New Dish (" chicken ", false, 400, Dish. The MEAT),
New Dish (" French fries ", true, 530, Dish. The OTHER),
New Dish (" rice ", true, 350, Dish. The OTHER),
New Dish (" season fruit ", true, 120, Dish. The OTHER),
New Dish (" pizza ", true, 550, Dish. The OTHER),
New Dish (" prawns, "false, 300, Dish. The FISH),
New Dish (" salmon ", false, 450, Dish. The FISH)
). The stream ();
@ Test
Public void testGp () {
Final Map AllQueryParam=menu. Collect (Collectors. GroupingBy (Dish: : isVegatarian, Collectors, counting ()));
AllQueryParam. ForEach ((vegatarian, total) - & gt; {
System. The out. Println (" Dish vegatarian: "+ vegatarian +", total: "+ total);
});
//the output:
//Dish vegatarian: false, total: 5
//Dish vegatarian: true, total: 4
}

CodePudding user response:

Try the best is to do a management system, in a main method in exercise don't have much meaning
  • Related