/ Backend Development

Split Text and Number and return the text only

Creator Image
Bashar Alshaibani
15 Apr 2024 -
1 min Reading time
public static void main(String[] args){
        Scanner input = new Scanner(System.in);

        int guest = Integer.parseInt(input.nextLine());
        String bestGuest = "";
        int highestFun = 0;
        for(int x = 0; x < guest; x++){
            String line = input.nextLine();
            String[] parts = line.split(" ");
            String guestName = parts[0];
            int fun = Integer.parseInt(parts[1]);
            if(fun > highestFun) {
                highestFun = fun;
                bestGuest = guestName;
            }
        }
        System.out.println(bestGuest);
    }