NetBeans- NoSuchElementException - PullRequest
0 голосов
/ 09 июня 2019

Код работает правильно в командной строке Gitbash (GitHub).Однако, когда я компилирую и запускаю его в NetBeans, он дает мне NoSuchElement Exception.Буду признателен, если кто-нибудь сможет мне помочь с NetBeans.

     package MyApp;

     import java.util.Scanner;

     public class MyApp {
     /** 
     * Starts the program 
     * 
     * @param args command line arguments 
     */
     public static void main(String[] args) {
        // welcome the user to MyApp
        System.out.println("Welcome to MyApp");
        System.out.println();  // print a blank line

        // create a Scanner object named sc
        Scanner sc = new Scanner(System.in);

        // check if the number you enter is even or odd until choice isn't
        equal to "y" or "Y"
        String choice = "y";
        while (choice.equalsIgnoreCase("y")) {
            // get the integer from the user
            System.out.print("Enter an integer:   ");
            double integer = sc.nextDouble();

            // check whether it is even or odd
            if (integer % 2 == 0) {
              System.out.println("It is an even integer");
            } else {
                System.out.println("It is an odd integer");  ;
            }

            // see if the user wants to continue
            System.out.print("Continue? (y/n): ");
            choice = sc.next();
            System.out.println(); 
        }
    }
}
...