The point is, I created a roulette, at the start of the game, the player is given 10,000 points,

int allmoney=10000; 

The first bet cannot exceed 10,000

 if(summa>allmoney){ 

int summa This is our bet. If the bet is played, the summa value is multiplied by 2, and added to allmoney, it was so intended ... But at the end of the game, the program asks the question "Do you want to play again?", After answering "Yes" the game starts anew, and again

 int allmoney=10000; 

And I want to make it so that in the new game this value was equal to the value from the previous game.

 import java.io.UTFDataFormatException; import java.util.Scanner; 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() { String[] colors = {"Черное", "Красное"}; String[] parity = {"Четное", "Нечетное"}; int allmoney=10000; Random random = new Random(); Scanner scanner = new Scanner(System.in, "UTF-8"); boolean isPlaying = true; while (isPlaying) { System.out.println("Сделайте вашу ставку. Вы можете поставить на Красное или Черное, на Четное или Нечетное."); String stavka = scanner.next(); System.out.println("Какую сумму ставите?"); int summa = scanner.nextInt(); if(summa>allmoney){ System.out.println("У вас не хватает денег для этой ставки."); break; } int colorIndex = random.nextInt(colors.length); int number = random.nextInt(36); System.out.println("Выпало " + parity[number % 2] + " " + number + " " + colors[colorIndex]); if (stavka.equals(colors[colorIndex]) || stavka.equals(parity[number % 2]) || stavka.equals(number)) { System.out.println("Ставка сыграла, вы победили! Выигрыш составляет: " + summa * 2); } else { System.out.println("Вы проиграли"); allmoney=allmoney-summa; } System.out.println("Делаем ставку еще раз?"); String otvet = scanner.next(); if (otvet.equals("Да")) { System.out.println("Продолжаем!"); } if (otvet.equals("Нет")) { isPlaying = false; playAgain = false; System.out.println("Жаль. До встречи!"); } } } } 

    1 answer 1

    make int allmoney=10000; beyond the limits of the Game() , so it does not overwrite.

      if (stavka.equals(colors[colorIndex]) || stavka.equals(parity[number % 2]) || stavka.equals(number)) { System.out.println("Ставка сыграла, вы победили! Выигрыш составляет: " + summa * 2); // далее нужно эту сумму прибавить к общей allmoney = allmoney + summa * 2; } 

    after your amount will be saved when you re-play