Students with maximum average score of three subjects | Java program to find the list of students having maximum average score ; Function to find the list of students having maximum average score Driver code ; Variables to store average score of a student and maximum average score ; List to store names of students having maximum average score ; Traversing the file data ; finding average score of a student ; Clear the list and add name of student having current maximum average score in the list ; Printing the maximum average score and names of students having this maximum average score as per the order in the file . ; Driver code ; Number of elements in string array
import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static void getStudentsList ( String [ ] file ) { int avgScore ; int maxAvgScore = Integer . MIN_VALUE ; ArrayList < String > names = new ArrayList < > ( ) ; for ( int i = 0 ; i < file . length ; i += 4 ) { avgScore = ( Integer . parseInt ( file [ i + 1 ] ) + Integer . parseInt ( file [ i + 2 ] ) + Integer . parseInt ( file [ i + 3 ] ) ) / 3 ; if ( avgScore > maxAvgScore ) { maxAvgScore = avgScore ; names . clear ( ) ; names . add ( file [ i ] ) ; } else if ( avgScore == maxAvgScore ) names . add ( file [ i ] ) ; } for ( int i = 0 ; i < names . size ( ) ; i ++ ) { System . out . print ( names . get ( i ) + " ▁ " ) ; } System . out . print ( maxAvgScore ) ; } public static void main ( String args [ ] ) { String [ ] file = { " Shrikanth " , "20" , "30" , "10" , " Ram " , "100" , "50" , "10" } ; getStudentsList ( file ) ; } }