+ 1
Why can't the Switch method be called?
The program can't use the user's input as a parameter for the switch method. What am I doing wrong? https://code.sololearn.com/cuNfAyG2BXXc
2 Answers
+ 8
Your nextLine call is your problem. Change it to next and it runs.
if you enter 2.7 1.3 Add on one line, oPerator gets ' Add'.
if you enter on separate lines, nextLine gets the empty string after 1.3 to eol.
+ 9
One of the best tricks for testing code is put debugging output in the program temporarily. I put a System.out.println("'"+oPerator+"'"); before the switch and there was the answer. I myself am still learning Java (though I've decades of programming experience) so I wasn't able to figure it out by looking. Now, I will know for next time.