New course! Every coder should learn Generative AI!
Try a free lesson0
I get "execution timed out" error ..... why?
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number = scanner.nextInt(); //take input and output corresponding message /* 1 => Language selection 2 => Customer support 3 => Check the balance 4 => Check loan balance 0 => Exit */ do{ switch(number){ case 1: System.out.println("Language selection"); break; case 2: System.out.println("Customer support"); break; case 3: System.out.println("Check the balance"); break; case 4: System.out.println("Check loan balance"); break; case 0: System.out.println("Exit"); break; } }while (number != 0); } }
4 Answers
+ 3
No Way!
You only take User input once and then go into the do while loop. Inside the loop, you are not updating the input value, so when the first input is not equal to 0, the loop will run for ever.
+ 3
I got it thank you guys
0
I dont get it, how can I make it work.
For me it looks correct.
If the number isnt 0 it goes in the switch.
And if its 0 it give EXit.