I'm trying to make an application that reads a file and writes the sum of the numbers, the average, the number of numbers in the file, but I get an error
Exception in thread "main" java.util.InputMismatchException
t java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextDouble(Scanner.java:2413)
at TestGradesAnalysis.main(TestGradesAnalysis.java:30)
Java Result: 1
Can you help me fix the error?
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.FileReader;
import java.io.*;
public class TestGradesAnalysis {
public static void main(String args[]) throws IOException {
PrintWriter outFile = new PrintWriter(new FileWriter("File.dat"));
double sum = 0;
int count = 0;
double max = 0;
double min = 0;
while (in.hasNextDouble()) {
sum = sum + in.nextInt();
count++;
if (in.nextDouble() > max) {
max = in.nextDouble();
}
if (min > in.nextDouble()) {
min = in.nextDouble();
}
}
double average = sum / count;
outFile.println("average is" + average);
outFile.println("max is" + max);
outFile.println("min is " + min);
outFile.println("number of grades is" + count);
}
This is my code
These are the contents of the File.dat
28 28 28 2008 510 September 89, 2116