This program is a game of "Roulette", the player must bet on red or black, pair or not pair, the problem is this, the player always wins if he writes string = "Red" Black "" Pair "Unpaired", for example, the player wrote that puts on Red, and black fell out, but the player won anyway, I understand the reason, but I can’t fix it because I don’t know how, I’m familiar with java for 3 days. The problem is in this block of code:
if (stavka.equals("Красное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else if (stavka.equals("Черное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else if (stavka.equals("Не четное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else if (stavka.equals("Четное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else A player wins if he writes any of the options listed above, but it must be done so that he would win only if his bet coincides with what fell out.
import java.util.Scanner; import java.util.Random; public class Bender { static boolean playAgain = true; public static void main(String[] args) { while (playAgain) { Game(); } } public static void Game() { Scanner scanner = new Scanner(System.in); int summa; String stavka; System.out.println("Здравствуйте в рулетке, на что ставите?Красное или Черное?Парное или не Парное?"); stavka = scanner.next(); System.out.println("Какую сумму ставите?"); summa = scanner.nextInt(); for (int i = 0; i < 1; i++) { int b; String[] colour = {"Черное.", "Красное."}; Random random = new Random(); Random random1 = new Random(); int select = random.nextInt(colour.length); b = (random1.nextInt(36)); if (b == 0) { System.out.print(""); } else if ((b & 1) == 0) { System.out.print(" Выпало четное" + " "); } else { System.out.print("Выпало нечетное" + " "); } System.out.println(b + " " + colour[select]); } if (stavka.equals("Красное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else if (stavka.equals("Черное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else if (stavka.equals("Не четное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else if (stavka.equals("Четное")) { System.out.println("Ставка сыграла, вы победили!Выиграшь составляет:" + summa * 2); } else playAgain = false; System.out.println("Вы проиграли,делаем ставку еще раз?"); String otvet; otvet = scanner.next(); if (otvet.equals("Да")) { System.out.println("Продолжаем!"); playAgain = true; } if (otvet.equals("Нет")) { System.out.println("Жаль(До Встречи!"); } } }
&&:stavka.equals("Чётное") && (b&1==0)- vp_arth