Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to write a score in java, manually enter the score of 10, remove a highest score, remove a lowest score, and average the remaining numbers?
How to write a score in java, manually enter the score of 10, remove a highest score, remove a lowest score, and average the remaining numbers?
Output result diagram:

The reference code is as follows:

Import? Java . util . ArrayList;

Import? Java . util . collections;

Import? Java . util . list;

Import? Java . util . scanner;

Public? Class? xxx? {

Public? Static electricity Invalid? main(String[]? args)? {

System.out.println ("Please enter 10 numbers separated by commas:");

Scanner? Scanner = new? Scanner (system. in);

String? input = scanner . next();

//Divide the input numbers into arrays according to ","

String[]? numStrs=input.split(",");

List < integer >? nums=new? ArrayList & lt integer & gt ();

//Put the array numbers into the collection list, which is convenient for sorting and taking out the largest and smallest numbers.

For what? (int? Me? =? 0; ? Me? & lt? numStrs.length? i++)? {

nums . add(integer . parse int(num strs[I]));

}

collections . sort(nums);

System.out.println ("After sorting from small to large:"+nums);

nums . remove(0);

nums . remove(nums . size()- 1);

System.out.println ("After removing the minimum number and the maximum number:"+nums);

Double? avg = 0d

int? sum = 0;

//Find the sum of the remaining numbers.

For what? (int? Me? =? 0; ? Me? & lt? nums . size(); ? i++)? {

sum+= nums . get(I);

}

//Average value (sum/remaining digits)

avg = sum/(nums . size());

The average value of System.out.println ("["+nums+"] is"+avg);

}

}