13,738,803 members
See more:
I have problem ,How can do this code?

----------------------------------------------------
### Welcome to Uber Fare Calculator ###
----------------------------------------------------
| 1 : Get fare information about available rides |
| 2 : Get a Fare Estimate for your Journey |
| 3 : Submit Rating of your Ride |
| 4 : Exit and display summary |
----------------------------------------------------

----------------------------------------------------
### Welcome to Uber Fare Calculator ###
----------------------------------------------------
| 1 : Get fare information about available rides |
| 2 : Get a Fare Estimate for your Journey |
| 3 : Submit Rating of your Ride |
| 4 : Exit and display summary |
----------------------------------------------------

-------------------------------------
*** RIDES ***
-------------------------------------
| X or x : UberX |
| L or l : UberXL |
| B or b : UberBlack |
-------------------------------------

What I have tried:

```Scanner t = new Scanner(System.in);
int cho;
do {
System.out.println("----------------------------------------------------");
System.out.printf("%-11s%10s%11s", "###", "Welcome to Uber Fare Calculator", "###\n");
System.out.println("----------------------------------------------------");
System.out.println("| 1 : Get fare information about available rides   |");
System.out.println("| 2 : Get a Fare Estimate for your Journey         |");
System.out.println("| 3 : Submit Rating of your Ride                   |");
System.out.println("| 4 : Exit and display summary                     |");
System.out.println("----------------------------------------------------");
cho = t.nextInt();
}while(cho<1 || cho>4);
```

I want when the user enter 1,2,3 or 4 go to another loops but when the user enter another choose i want this massage
```System.out.println("\n\t\tInvalid Choice!! Please Try again");
```
Posted 14-Nov-17 7:38am
Updated 14-Nov-17 8:06am

## Solution 1

`do ... while` continues to loop while teh condition is true:
```i = 0;
do {
System.out.println(i);
i = i + 1;
} while (i < 5);```
Will print:
```0
1
2
3
4```
Your condition is only true when `cho` is either less than 1 or greater than 4: it is false for all values of `cho` in the set {1, 2, 3, 4}
So when a user enters a valid menu choice, it immediately exits the loop.
14-Nov-17 14:10pm

Where I can add this code
OriginalGriff 14-Nov-17 14:25pm

As part of the code you have yet to write to handle your menu choices! If you don't find a valid choice, you print that and go round again.

Top Experts
Last 24hrsThis month
 OriginalGriff 238 Richard MacCutchan 195 CPallini 105 Manish K. Agarwal 85 Jason Gleim 75
 OriginalGriff 5,856 Richard MacCutchan 2,164 Patrice T 1,642 CPallini 1,334 Dave Kreskowiak 1,225