That code won't even compile - which is probably why its doesn't work as expected!
Unless your code compiles with no errors, it doesn't produce an executable file - so when you try to run the "latest code" what executes is the previous version that did.
Java does not have any concept of
while ... else ...
so that code doesn't compile.
In addition, if you look for "1" in a string and find it, you will never get to check for "10" in the same string. Conversely, if you look for "1" in a string and don't find it, you will never find a match for "10" in the same string!
What I would do is stop faffing with strings: when the user enters a menu option, convert it to an integer (reporting a problem if what he entered is not convertible) and pass that numeric value to your function instead.
I'd also suggest that you look at the
switch[
^] statement as well, instead of a series of "
else if
" lines. Or use an array of strings instead of that code ...