名前と年齢を交互に切り替えるリストがテキストファイルにあります。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
名前を年齢と一致させるために私はただ見ることができないすべてがコンパイルされます。ヘルプ?