i have to write a program that reads names and ages from the user until an empty line is entered. The name and age are separated by a comma.After reading all user input, the program prints the age of the oldest person. Now i'm using the following method
import java.util.Scanner;
public class AgeOfTheOldest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true){
String text = scanner.nextLine();
if(text.equals("")){
break;
}else{
String[] pieces = text.split(",");
int[] ages = Integer.valueOf(pieces[1]);
}
}
}
}
But the int[] ages line gives me this errorenter image description here so how do i convert string values and assign it to an integer array?