JAVA array instance-calculate the maximum score of a student, obtain the maximum and minimum values in the array, and obtain the Student Score Array
Instance:
Import java. util. *; // obtain the maximum score of a student: public class Test {public static void main (String [] args) {System. out. println ("======== maximum score of students ========"); score in = new score (System. in); int [] arr = new int [5]; // obtain the score of each student entered by the user (int I = 0; I <arr. length; I ++) {System. out. println ("Enter the" + (I + 1) + "Student Score"); arr [I] = in. nextInt () ;}// calculate the maximum value int max = arr [0]; for (int I = 0; I <arr. length; I ++) {if (max <arr [I]) {max = arr [I] ;}}
// If you want to calculate the minimum value, you only need to change the smaller value above to the greater value, and the System. out. println ("maximum value:" + max) is done );}}
Running result