Jump in rank of a student after updating marks | Java implementation of the approach ; Function to print the name of student who stood first after updation in rank ; Array of students ; Store the name of the student ; Update the marks of the student ; Store the current rank of the student ; Print the name and jump in rank ; Driver code ; Names of the students ; Marks of the students ; Updates that are to be done ; Number of students
import java . util . * ; class GFG { static class Student { String name ; int marks , prev_rank ; Student ( ) { this . marks = 0 ; this . prev_rank = 0 ; } } static void nameRank ( String [ ] names , int [ ] marks , int [ ] updates , int n ) { Student [ ] x = new Student [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = new Student ( ) ; x [ i ] . name = names [ i ] ; x [ i ] . marks = marks [ i ] + updates [ i ] ; x [ i ] . prev_rank = i + 1 ; } Student highest = x [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { if ( x [ j ] . marks >= highest . marks ) highest = x [ j ] ; } System . out . print ( " Name : ▁ " + highest . name + " , ▁ Jump : ▁ " + Math . abs ( highest . prev_rank - 1 ) ) ; } public static void main ( String [ ] args ) { String [ ] names = { " sam " , " ram " , " geek " } ; int [ ] marks = { 80 , 79 , 75 } ; int [ ] updates = { 0 , 5 , - 9 } ; int n = marks . length ; nameRank ( names , marks , updates , n ) ; } }