I need to create a program that receives 3 user inputs in the form:
Name1 (any number of spaces) age1
Name2 (any number of spaces) age3
Name3 (any number of spaces) age3
Then print the line that has the highest age (suppose Name3 age3 had the highest age that I would print on my line).
My code is:
import java.util.*;
public class RankAge{
public static void main(String[] args){
System.out.println("Enter 3 different names and the age of each person respectively:");
Scanner sc = new Scanner(System.in);
String n1 = sc.nextLine();
String n2 = sc.nextLine();
String n3 = sc.nextLine();
}
}
I know how to scan user inputs, but I donβt know how to compare the numbers inside the resulting string to print a specific one (also, since there can be any number of spaces that seems even more complicated to me).
source
share