question : In the Singing contest, a total of 10 judges scored, in the calculation of the singer score, remove a maximum score, remove a minimum score, and then the remaining 8 judges scored average, is the player's final score. Enter the score for each jury and ask for a player's score.
Analysis: The key to this problem is that when the highest and lowest points occur multiple times, how to deal with the highest and lowest points can only be removed once. You can set a Boolean value so that the remove operation is performed only once.
Test method:
1 Public Static voidTest () {2Scanner sc =NewScanner (system.in);3SYSTEM.OUT.PRINTLN ("The performance is complete, please judge the judges:");4 int[] A =New int[10];5 for(inti=0;i<10;i++){6 intScore =sc.nextint ();7A[i] =score;8 }9System.out.println ("The 10 judges ' ratings were:"));Ten Show (a); One int[] B =Getscore (a); ASystem.out.println ("Remove a highest score, a minimum score after:"); - Show (b); - Getavg (b); the -}
Printing method:
// iterating through an array Public Static void Show (int[] a) { for (int i = 0; i < a.length; i++) { System.out.print (A[i]+ ""); } System.out.println (); }
Gets the maximum element:
// To find the maximum value Public Static int getmax (int[] a) { int max = a[0]; for (int i = 0; i < a.length; i++) { if(a[i]>max) { = A[i]; } } return Max; // System.out.println ("The largest element of the array is:" +max); }
Gets the minimum element:
// To find the minimum value Public Static int getmin (int[] a) { int min = a[0]; for (int i = 0; i < a.length; i++) { if(a[i]<min) { = A[i]; } } return min; // System.out.println ("The smallest element of the array is:" +min); }
Get a new scoring array:
//Scoring Methods//parameters: Array of scores//return value: Removes the array after the highest and lowest points Public Static int[] Getscore (int[] a) { intMax =Getmax (a); intMin =Getmin (a); intL = a.length-2; int[] B =New int[L]; intCount = 0;//counter BooleanFlag1 =true; BooleanFlag2 =true; for(inti=0;i<a.length;i++) {//assigns the value of the original array to the new array selectively if(a[i]==max&&flag1==true) {Flag1=false; Continue; } if(a[i]==min&&flag2==true) {Flag2=false; Continue; } if(count<l) {B[count]=A[i]; Count++; } } returnb; }
Get the final average score:
// Find Average Public Static void getavg (int[] a) { int sum = 0; for (int i = 0; i < a.length; i++) { sum+ =a[i] ; } int avg = sum/a.length; System.out.println ("The contestant Final score:" +avg); }
Java Basics-Singer scoring function realization