我在一个文本文件中有一个在姓名和年龄之间交替的列表。有9个名字和9个年龄。
我需要我的程序来显示
人(在此处插入姓名)具有最高年龄:(在此处插入年龄)。
到目前为止,这是我的代码:
public class Names
{
public static void main(String[] args) throws Exception
{
// get textfile
Scanner input = new Scanner( new File("names_and_ages.txt") );
final String[] names= new String[9];
final int[] ages= new int[9];
int counter = 0;
while (input.hasNext()) //while not end-of-file
{
names[counter]=input.next();
ages[counter]=Integer.parseInt(input.next());
counter++;
}
highestAge(names, ages);
input.close();
}//end of main
public static void highestAge (String[] name, int[] age)
{
String name;
int count = 0;
int oldest = highestAge[count];
for ( int number: highestAge)
{
if (number > oldest)
{
oldest = number;
}
}
System.out.print("Person " + name + " has the highest age: " + oldest );
}//end of Size method
}//end of class
一切都编译了,我只是看不到使名称与年龄相匹配。帮助?