0

私はJavaで少し勉強して「遊ぶ」ようになりました。私はコンピューター工学の学生です (昨年は C を勉強しました)。しかし、今日、「ファイルからのスキャン」で問題が発生しました。私はEclipseで作業しており、これを含むファイルテキスト「in.txt」を作成した後:

20 31,12 Luca

私はコンパイラによって与えられたのと同じエラーで立ち往生しました:

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.nextDouble(Scanner.java:2413)
at it.devapp.corsojava.esempi.FileScanner.main(FileScanner.java:20)

ポイントは何ですか?エラーが見つかりません。これはコードです:

public class FileScanner {

public static void main(String[] args) 

        throws FileNotFoundException { // needed for file operations

    int num1;
    double num2;
    String name;
    double sum;
    // Scanning input operations

    Scanner in = new Scanner(new File("in.txt"));

    num1 = in.nextInt();
    num2 = in.nextDouble();
    name = in.next();

    // Display
    sum = num1 + num2;
    System.out.println("The integer read is: " + num1);
    System.out.println("The floating point number read is: " + num2);
    System.out.println("The string read is: " + name);
    System.out.println("Hi " + name +", the sum of " + num1 + " and " + num2  + " is: " + sum );
    in.close();
    }
 }

みんなありがとう!:)

4

0 に答える 0