JAVA Scanner

Asked 2 years ago, Updated 2 years ago, 31 views

int menu = scanner.nextInt(); System.out.print("The menu you want" + menu + "Is the number correct? (Y/N):"); String yn = scanner.next();

And then If you enter Y, the menu + "Number" order has been completed." If you enter N, please select the menu again." I'd like to print out.

I tried to write if(yn == y) but I got an error. Can't string be used as a conditional expression like int?

java

2022-09-22 22:56

1 Answers

Use in the form of yn == y to compare where the string is stored. If you want to compare the contents of a string, you must use it in the form of yn.equals(y).


2022-09-22 22:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.