0

Press 2 to contact customer support

You are creating an automated phone system for bank clients. Number selections should activate the actions noted below as follows: 1 => Language selection 2 => Customer support 3 => Check account balance 4 => Check loan balance 0 => Exit You can use the first 4 commands in a random sequence without interrupting the phone call - only the number 0 does. Write a program that will continuously take a number as input and output the corresponding message, until the client enters 0. Sample Input 1 4 3 0 Sample Output Language selection Check loan balance Check the balance Exit Here is my code: https://code.sololearn.com/cPdw0xPz5I3p/?ref=app Can you please tell me what's wrong in this code. I tried with this code. But still the compiler is showing exception errors!

13th Sep 2021, 5:53 AM
Tanzim Ikram Sheikh
Tanzim Ikram Sheikh - avatar
2 Respostas
+ 2
your code is fine, you will get exception handling error. when the input does not contain a 0 to exit. because once you hit submit in sololearn, you will not be asked to enter a number again. so do{ }while () will crash, as there's no more input to compare. input must be entered all at once in multiple lines. for example : 3 2 4 2 0
13th Sep 2021, 6:06 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
package learningcoding; import java.util.Scanner; //jq public class lesson12 { public static void main(String[] args) { Scanner choice = new Scanner(System.in); int num1; int num = choice.nextInt(); //for do while loop if int num1 ouside the loop it will cause infinite loops; switch (num) { 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; default: System.out.println("Exit"); } System.out.println(); do { num1 = choice.nextInt(); if (num1 == 1) { System.out.println ("Language selection"); } else if (num1 == 2) { System.out.println("Customer support"); } else if (num1 == 3) { System.out.println("Check the balance"); } else if (num1 == 4) { System.out.println("Check loan balance"); } } while (num1 != 0); System.out.println("Exit"); } } your input outside the loop will cause running forever
21st Sep 2021, 5:37 AM
jiaqi chen
jiaqi chen - avatar