私はまだJavaにかなり慣れていません。クラス用にこのプログラムを作成しましたが、今までにないエラーが発生します。誰かがそれを助けることができれば、それは素晴らしいことです。ありがとうございました!
import java.util.Scanner;
import java.io.*;
public class grades {
public static void main(String[] args) throws IOException {
// Define file names
final String INPUT_FILE = "gradesinput.txt";
final String OUTPUT_FILE = "gradesoutput.txt";
// define variables
int grade;
String name = null, filename;
double value = 0;
String msg;
// Access the input/output files
File inputDataFile = new File(INPUT_FILE);
Scanner inputFile = new Scanner(inputDataFile);
FileWriter outputDataFile = new FileWriter(OUTPUT_FILE);
PrintWriter outputFile = new PrintWriter(outputDataFile);
System.out.println("Reading file " + INPUT_FILE + "\r\n" +
"Creating file " + OUTPUT_FILE);
// Read all of the values from the file
while (inputFile.hasNext()) {
grade = inputFile.nextInt();
name = inputFile.nextLine();
name = name.trim();
} // End while
if(value >= 90)
{
msg = "OUTSTANDING";
}
else if (value >= 70)
{
msg = "Satisfactory";
}
if(value >= 90){
msg = "OUTSTANDING";
}else{
if(value >= 70){
msg = "Satisfactory";
}else
msg = "FAILING";
}
outputFile.println(value + " " + name + " " + msg);
outputFile.println("processed names");
outputFile.println("between 70 and 89 inclusive");
outputFile.close();
} // End outputResults
} // End class
次のエラーが表示されます。
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at grades.main(grades.java:37)