title: How to start over again in Java?
body: <p>I have this following program  and I want to have a loop that asks the user if he wants to play again and if he wants the program or the play starts over again.</p>
  
  <pre><code>import java.util.*;
  
  public class Crapl {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          double budget;
          int toGo = 1;
          while (toGo == 1) {
              Scanner input = new Scanner(System.in);
              System.out.print("What is your budget");
              budget = input.nextDouble();
              play(budget);
          }
      }
      // rool method
  
      public static int roll() {
          Random ran = new Random();
          int dice1, dice2;
  
          dice1 = ran.nextInt(6) + 1;
          dice2 = ran.nextInt(6) + 1;
          System.out.printf("\tYou rolled %d+%d=%d\t", dice1, dice2, dice1 + dice2);
          return dice1 + dice2;
      }
  
      public static void play(double budget) {
          int con, gamePoint, game;
          int toGo = 1;
          con = 0;   //game will continue
          double bet, budget2, userCredit = 0;
          Scanner get = new Scanner(System.in);
          gamePoint = 0;
          budget2 = budget;
  
          System.out.printf("You have $%.2f available balance, how much you want to bet:\n", budget);
          bet = get.nextDouble();
  
          while (bet &gt; budget) {
              System.out.printf("You ONLY have $%.2f available balance, how much you want to bet:\n", budget);
              bet = get.nextDouble();
          }
  
          if (budget == 0.00) {
              System.out.printf("you have $%.2f balance , so you cant play anymore ", budget);
          }
  
          budget = budget - bet;//withdraw amount from budget
          game = roll(); //play game
  
          switch (game) {
              case 2:
              case 3:
              case 12:
                  con = -1; //game lost
                  System.out.printf("Sory you have lost the game. Your remaining balance is $%.2f\n", budget);
                  break;
              case 7:
              case 11:
                  con = 1;
                  System.out.printf("You won the game. Your remaining balance is $%.2f\n", budget + 2 * bet);
                  break;
              default:
                  con = 0;
                  gamePoint = game;
                  System.out.printf("Game point is %d\n", gamePoint);
          }
  
          while (con == 0) {
              System.out.printf("\nYou have $%.2f available balance, how much you want to bet:\n", budget);
              bet = get.nextDouble(); //one loop
              while (bet &gt; budget) {
                  System.out.printf("You ONLY have $%.2f available balance, how much you want to bet:\n", budget);
                  bet = get.nextDouble();
              }
  
              budget -= bet; //withdraw the bet from budget
              userCredit += bet; //keep adding total bet into userCredit.
              game = roll();
  
              if (game == 7) {
                  con = -1;
                  System.out.printf("\nSory you have lost the game. Your remaining balance is $%.2f\n", budget);
              } else if (game == gamePoint) {
                  con = 1;
                  budget2 += userCredit;
                  System.out.printf("\nYou have won the game. Your remaining balance is $%.2f\n", budget2);
  
                  System.out.printf("Would you like to play again?\n");
                  System.out.printf("If yes enter 1 0 otherwise\n");
                  toGo = get.nextInt();
              }
          }
      }
  }
  </code></pre>