I study Java, but I still don’t know enough deeply. There is a need for such a code - the game 21.

The user received 2 cards on his hands and they ask him - are they ready to continue? If he enters Y , then the method that gives the card is triggered a third time; if N , the exit method is triggered, and the move goes to the croupier.

I'm trying to "pull" it all on

 Scanner scanner = new Scanner(System.in); 

and something like

 if (scanner.equals(Y)) { то то и то то } else { что то другое } 

I also tried to shove two answer choices in the switch, but something did not work.

Please direct the true path :)

  • You can use an infinite loop with a given exit condition. - Uladzimir Khadakouski
  • It turned out like this: if (a.equals (y)) {firstCard.lookCard (); } if (a.equals (n)) {System.out.println ("Goodbye"); } if (! Objects.equals (a, y) &&! Objects.equals (a, n)) {System.out.println ("Invalid version"); System.exit (0); } But I'm more than sure that this is pornography and not code. - RattenGW

1 answer 1

 Scanner in = new Scanner(System.in); boolean b = true; while (b) { String string = in.next().toLowerCase(); switch (string) { case "y": // дать карту break; case "n": // сделать что то другое; b = false; break; default: System.out.println("Вы ввели неверное значение."); } }