Getting Scanner Errors On Mac OSX

2019-02-21 05:02发布

I recently purchased Scite for Mac but am having issues using the Scanner class. Compiles fine, but when I run it I get errors.

This is the code. Works fine on Windows but cannot get to work on Mac OSx.

   `import java.util.Scanner;
    public class Power2Input{
    public static void main(String[]args){
    Scanner input=new Scanner(System.in);
    System.out.println("Enter TWO integer numbers!");
    int a=0;
    System.out.println("First number: ");
    a=input.nextInt();
    int b=0;
    System.out.println("Second number: ");
    b=input.nextInt();
    double c=Math.pow(a, b);
    System.out.println((int)c);
}

}`

This is the error message.

    `Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Power2Input.main(Power2Input.java:10)`

0条回答
登录 后发表回答