このメソッドを使用して、Spotify zipfsong パズルの入力を取得しています: https://www.spotify.com/us/jobs/tech/zipfsong/
public static ArrayList<ArrayList<String>> fileReader() throws IOException {
    Scanner scanner = new Scanner(System.in);        
    ArrayList<ArrayList<String>> fileContents = new ArrayList<ArrayList<String>>();
    try{                    
        String currentLine = scanner.nextLine();                
        ArrayList<String> fileRow = new ArrayList(Arrays.asList(currentLine.split(" ")));
        fileContents.add(fileRow);
        int numberOfInputLines = Integer.parseInt(fileRow.get(0));
        int numberOfOutputLines = Integer.parseInt(fileRow.get(1));
        if (numberOfInputLines < numberOfOutputLines) {
            return null;
        }
        for (int lineCount = 0; lineCount < numberOfInputLines; lineCount++) {
            currentLine = scanner.nextLine();               
            fileRow = new ArrayList(Arrays.asList(currentLine.split(" ")));
            fileContents.add(fileRow);                          
        }            
    } catch(Exception e) { 
        System.out.println("Read Error");       
        return null;
    } finally {
        scanner.close();
    }       
    return fileContents;
}
だから、基本的には最初の行を読んで、次に来る行の数を見つけてから、スキャナーを使用してそれらを読み取ります。さて、何らかの理由で ArrayIndexOutOfBoundsException を取得し続けます。この入力方法のせいでしょうか??