简单的scannerI / O演示中的java.util.InputMismatchException

时间:2014-09-28 17:41:12

标签: java eclipse string exception

我看不出错误在哪里? eclipse在“System.out.println”中输入调试当前点(“你输入:\”“+ s1 +”\“”);“但我觉得没有错。 你可以帮帮我吗?我是java的新手。

public class Scannerdemo {

public static void main(String[] args){
    Scanner keyboard = new Scanner(System.in);

    System.out.println("enter two whole numbers:");
    System.out.println("separated by one or more spaces:");

    int n1, n2;
    n1 = keyboard.nextInt();
    n2 = keyboard.nextInt();
    System.out.println("you entered " + n1 +"and "+ n2);

    System.out.println("next enter two numbes.");
    System.out.println("a decimal point is OK.");

    double d1, d2;
    d1 = keyboard.nextDouble();
    d2 = keyboard.nextDouble();
    System.out.println("you entered " + d1 + "and " + d2);
    System.out.println("next enter two words:");

    String s1, s2;
    s1 = keyboard.next();
    s2 = keyboard.next();
    System.out.println("you entered \"" + s1 + "\" and \"" + s2 + "\"");

    s1 = keyboard.nextLine();

    System.out.println("next enter a line of text:");
    s1 = keyboard.nextLine();
    System.out.println("you entered: \"" + s1 + "\"");

}
}

0 个答案:

没有答案