Проблема с получением вменения от пользователя и сравнением его (очистить и выйти из вариантов в простом калькуляторе)
public class Lab05c { public static void main( String[] args) { Scanner scan = new Scanner( System.in); // constants // variables double currentResult; String userEntry; char sum; char subtraction; char multiplication; char division; double enteredNumber; char operation; String userEntryUntouched; // program code currentResult = 0 ; sum = '+'; subtraction = '-'; multiplication = '*'; division = '/'; System.out.println("Welcome to Simple Calculator!"); do { System.out.println(currentResult); System.out.println("+,-,*,/ value") ; System.out.println("Clear") ; System.out.println("Quit") ; System.out.println("Select: ") ; userEntry = scan.nextLine() ; userEntryUntouched = userEntry ; operation = userEntry.charAt(0); userEntry = userEntry.replaceAll("\\D+",""); enteredNumber = Double.parseDouble( userEntry ) ; if ( userEntryUntouched == "Clear" || userEntryUntouched == "C" || userEntryUntouched == "c" ) { currentResult = 0 ; } if ( operation == sum ) { currentResult = currentResult + enteredNumber ; } if ( operation == subtraction ) { currentResult = currentResult - enteredNumber ; } if ( operation == multiplication ) { currentResult = currentResult * enteredNumber ; } if ( operation == division ) { currentResult = currentResult / enteredNumber ; } } while (userEntryUntouched != "Quit" ) ; } } // end class <!-- end snippet --> This is my code for a simple calculator. When I type Clear or Quit i get the error : java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source) at sun.misc.FloatingDecimal.parseDouble(Unknown Source) at java.lang.Double.parseDouble(Unknown Source) at Lab05c.main(Lab05c.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:267) but it does the calculations correctly. Although I tried so hard to find what's wrong, I was not able to find it. Why i get a error when i type Quit and Clear? Thank you very much for your helps... ( I also tried running this code with .equals() code but still didn't work)
Что я уже пробовал:
Я попробовал другой код .equalsto (), но он тоже не сработал.