Skip to content
Advertisement

Trying to understanding Exit, Loop, Method and If and Else [JAVA]

Hello guys I need help with my code. I am trying to understand how to use the method, loop,if-else statement, and exit code. So I’m writing a simple calculation base on the user choice but right now I can’t figure out how to make the input read to loop back when user input else than the number (mean no alphabet are allowed) and it will continue back to the option till the user enter the right option that is either 1 or 2.

Do let me know if I make any mistake or is there a way to simplify this code more.

WANT OUTPUT TO BE LIKE THIS:-

JavaScript

CODE:-

JavaScript

Advertisement

Answer

I have updated your code :

JavaScript

Output :

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement