I keep getting an error with my code and I'm not sure how to fix it. The top portion is the error I'm receiving.
the objective of this program is to input a text file and format it into rows and columns.
This file contains Student names and 3 scores for each
Sample Input file:
Andy Borders
200
250
400
John Smith
120
220
330
I'm by no means asking for anyone to do it for me, I'm just new and unsure how to fix this.
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Project_5.main(Project_5.
-
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class Project_5
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter file name: ");
String fileName = in.nextLine();
System.out.printf("%s"+"%20s"+"%10s"+"%10s"+"%10s","Name","Score1","Score2","Score3");
System.out.print("\n");
System.out.print("------------------------------------------------------");
System.out.println("");
try {
File file = new File(fileName);
Scanner inputFile = new Scanner(file);
ArrayList<String> list = new ArrayList<String>();
while (inputFile.hasNext())
{
String Name = inputFile.nextLine();
int Score1 = inputFile.nextInt();
int Score2 = inputFile.nextInt();
int Score3 = inputFile.nextInt();
System.out.printf("%s"+"%9s"+"%10s"+"%10s",Name,Score1,Score2,Score3);
System.out.println("\n");
}
inputFile.close();
} catch (IOException e) {
System.out.println(
"There was a problem reading from " + fileName);
}
finally {
}
}
}