How to do the “do while loop” automated phone system 18.2 practice for java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to do the “do while loop” automated phone system 18.2 practice for java

/* I am having real trouble with this. I keep getting the or -> expected error. I do not know what that is. I am real new to coding. I feel like I’m close but maybe I am way off. Can someone please help me?*/ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number; do { //take input and output corresponding message /* 1 => Language selection 2 => Customer support 3 => Check the balance 4 => Check loan balance 0 => Exit */ number = scanner.nextInt(); 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 number = 0; System.out.println("Exit"); } } while(number != 0 || number < 5 || number >= 0); } }

13th Jan 2021, 12:21 AM
Guy Robbins
4 Answers
+ 1
Yes you where very close. 😉👍 https://code.sololearn.com/cHQ30L170u74/?ref=app
13th Jan 2021, 2:39 AM
Stefanoo
Stefanoo - avatar
0
Thank you so much for your help Stefanoo
13th Jan 2021, 3:03 AM
Guy Robbins
0
Hey Stefanoo all the tests pass except 3 and 4. What if the user inputs a value greater than 4 like 17. how do i get the code to continue to take input instead of just stopping.
13th Jan 2021, 11:20 PM
Guy Robbins
0
You could just write while(number != 0); So the program runs until you enter 0. I edit my code so you can see what I ment. 3 and 4 works for me? 🤔
14th Jan 2021, 7:21 AM
Stefanoo
Stefanoo - avatar