有一个排名、姓名和受欢迎程度的列表 1 Jake 21021(排名、实际姓名、当年有多少婴儿获得了这个名字)我试图将这三个独立的东西分成数组。这样,如果用户搜索“Jake”排名:1 会弹出,21021 也会弹出。这就是我目前所拥有的......
import java.util.*;
import java.io.*;
public class Test
{
public static void main(String[] args)
{
Scanner inputStream = null;
try
{
inputStream = new Scanner(new FileInputStream("src/boynames.txt"));
}
catch (FileNotFoundException e)
{
System.out.println("Sorry we couldn't find the requested file...");
System.out.println("Exiting...");
System.exit(0);
}
//Initializing the BOY Variables
int[] counter = new int[1];
String[] name = new String[1];
int[] popularity = new int[1];
//End of initializing BOY variables
for (int i=0; i <1000;i++)
{
counter[0] = 1;
name[i] = inputStream.next();
popularity[i]=inputStream.nextInt();
System.out.print(counter[i] + " " + name[i] + " " + popularity[i] );
counter[i] = counter[i] + 1 ;
}
}
}
我不断收到错误
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Test.main(Test.java:27)
任何帮助都是极好的!谢谢