Try:
System.out.print("X: "); x = Double.parseDouble(keyboard.nextLine()); System.out.print("Y: "); y = Double.parseDouble(keyboard.nextLine()); System.out.print("Op: "); op = keyboard.nextLine();
This will check the number you enter on Double and read the carriage return.
If you need error control (if the user enters a string instead of a number):
Boolean check = true; do { try { //The code to read numbers } catch(InputMismatchException e) { System.err.println("Please enter a number!"); check = false; } } while(check == false)
source share