title: I have an error that randomly happens when I input an int, does anybody know what's wrong?
body: <p>Ok, so i'm making a blackjack game for an end of year project in school, but when i chose to "stand" in a game, the code could randomly ignore my input and then stop working all together. Can anyone figure this out? neither me nor my teacher could. (I'm sorry there's so much code, i dont know if you will need all the classes to help me)</p>
  
  <p>Runner:</p>
  
  <pre><code>import static java.lang.System.*;
  import java.util.Arrays;
  
  public class BlackJackRunner
  {
     public static void main( String args[] )
      {
        Deck deck = new Deck();
        Game game = new Game();
        game.startGame();
        // work on resetting btwn each hand and still work on choices i think
     }
  }
  </code></pre>
  
  <p>Deck class:</p>
  
  <pre><code>public class Deck
  {
     public int[] card = new int[2];
     public String number = "";
     public Deck()
     {
  
     }
     public void drawCard()
     {
        int[] drawn = new int[2];
        int switc;
        //do{
        do{
           switc = Rndm.i(0, 51);
           String sw = switc + " ";
  
           if(number.indexOf(sw) == -1)
           {
              if (number.indexOf(sw) &gt; -1)
                 System.out.println("Problem!!");
              switch(switc)
              {
                 //face first, then suit;
                 //1 - spades   2-clubs  3-hearts 4-diamonds
  
  
                //2-10 - face value  j-11  q-12  k-13  a-1
                 case 0 : drawn[0] = 2;   drawn[1] = 1;   number = number + 0 + " ";   break; 
                 case 1 : drawn[0] = 3;   drawn[1] = 1;   number = number + 1 + " ";   break;
             case 2 : drawn[0] = 4;   drawn[1] = 1;   number = number + 2 + " ";   break;
             case 3 : drawn[0] = 5;   drawn[1] = 1;   number = number + 3 + " ";   break;
             case 4 : drawn[0] = 6;   drawn[1] = 1;   number = number + 4 + " ";   break;
             case 5 : drawn[0] = 7;   drawn[1] = 1;   number = number + 5 + " ";   break; 
             case 6 : drawn[0] = 8;   drawn[1] = 1;   number = number + 6 + " ";   break;
             case 7 : drawn[0] = 9;   drawn[1] = 1;   number = number + 7 + " ";   break;
             case 8 : drawn[0] = 10;   drawn[1] = 1;   number = number + 8 + " ";   break;
             case 9 : drawn[0] = 11;   drawn[1] = 1;   number = number + 9 + " ";   break;
             case 10 : drawn[0] = 12;   drawn[1] = 1;   number = number + 10 + " ";   break; 
             case 11 : drawn[0] = 13;   drawn[1] = 1;   number = number + 11 + " ";   break;
             case 12 : drawn[0] = 1;   drawn[1] = 1;   number = number + 12 + " ";   break;
             case 13 : drawn[0] = 2;   drawn[1] = 2;   number = number + 13 + " ";   break;
             case 14 : drawn[0] = 3;   drawn[1] = 2;   number = number + 14 + " ";   break;
             case 15 : drawn[0] = 4;   drawn[1] = 2;   number = number + 15 + " ";   break; 
             case 16 : drawn[0] = 5;   drawn[1] = 2;   number = number + 16 + " ";   break;
             case 17 : drawn[0] = 6;   drawn[1] = 2;   number = number + 17 + " ";   break;
             case 18 : drawn[0] = 7;   drawn[1] = 2;   number = number + 18 + " ";   break;
             case 19 : drawn[0] = 8;   drawn[1] = 2;   number = number + 19 + " ";   break;
             case 20 : drawn[0] = 9;   drawn[1] = 2;   number = number + 20 + " ";   break; 
             case 21 : drawn[0] = 10;   drawn[1] = 2;   number = number + 21 + " ";   break;
             case 22 : drawn[0] = 11;   drawn[1] = 2;   number = number + 22 + " ";   break;
             case 23 : drawn[0] = 12;   drawn[1] = 2;   number = number + 23 + " ";   break;
             case 24 : drawn[0] = 13;   drawn[1] = 2;   number = number + 24 + " ";   break;
             case 25 : drawn[0] = 1;   drawn[1] = 2;   number = number + 25 + " ";   break; 
             case 26 : drawn[0] = 2;   drawn[1] = 3;   number = number + 26 + " ";   break;
             case 27 : drawn[0] = 3;   drawn[1] = 3;   number = number + 27 + " ";   break;
             case 28 : drawn[0] = 4;   drawn[1] = 3;   number = number + 28 + " ";   break;
             case 29 : drawn[0] = 5;   drawn[1] = 3;   number = number + 29 + " ";   break;
             case 30 : drawn[0] = 6;   drawn[1] = 3;   number = number + 30 + " ";   break; 
             case 31 : drawn[0] = 7;   drawn[1] = 3;   number = number + 31 + " ";   break;
             case 32 : drawn[0] = 8;   drawn[1] = 3;   number = number + 32 + " ";   break;
             case 33 : drawn[0] = 9;   drawn[1] = 3;   number = number + 33 + " ";   break;
             case 34 : drawn[0] = 10;   drawn[1] = 3;   number = number + 34 + " ";   break;
             case 35 : drawn[0] = 11;   drawn[1] = 3;   number = number + 35 + " ";   break; 
             case 36 : drawn[0] = 12;   drawn[1] = 3;   number = number + 36 + " ";   break;
             case 37 : drawn[0] = 13;   drawn[1] = 3;   number = number + 37 + " ";   break;
             case 38 : drawn[0] = 1;   drawn[1] = 3;   number = number + 38 + " ";   break;
             case 39 : drawn[0] = 2;   drawn[1] = 4;   number = number + 39 + " ";   break;
             case 40 : drawn[0] = 3;   drawn[1] = 4;   number = number + 40 + " ";   break; 
             case 41 : drawn[0] = 4;   drawn[1] = 4;   number = number + 41 + " ";   break;
             case 42 : drawn[0] = 5;   drawn[1] = 4;   number = number + 42 + " ";   break;
             case 43 : drawn[0] = 6;   drawn[1] = 4;   number = number + 43 + " ";   break;
             case 44 : drawn[0] = 7;   drawn[1] = 4;   number = number + 44 + " ";   break;
             case 45 : drawn[0] = 8;   drawn[1] = 4;   number = number + 45 + " ";   break; 
             case 46 : drawn[0] = 9;   drawn[1] = 4;   number = number + 46 + " ";   break;
             case 47 : drawn[0] = 10;   drawn[1] = 4;   number = number + 47 + " ";   break;
             case 48 : drawn[0] = 11;   drawn[1] = 4;   number = number + 48 + " ";   break;
             case 49 : drawn[0] = 12;   drawn[1] = 4;   number = number + 49 + " ";   break;
             case 50 : drawn[0] = 13;   drawn[1] = 4;   number = number + 50 + " ";   break;
             case 51 : drawn[0] = 1;   drawn[1] = 4;   number = number + 51 + " ";   break;
  
          }
       }
    }while(drawn[0]==0 &amp;&amp; drawn[1]==0);
    //}while(number.indexOf(switc) &gt; -1);
    if (drawn[0]==0 &amp;&amp; drawn[1]==0)
       System.out.println("Problem!!");
  
  
       card[0] = drawn[0];
       card[1] = drawn[1];
  
  
    }
     public void shuffleDeck()
     {
        number = "";
     }
     public int[] getCard()
     {
        drawCard();
        return card;
     }
     public String toString()
     {
        return card[0] + " " + card[1];
     }
  }
  </code></pre>
  
  <p>Card class:</p>
  
  <pre><code>public class Card extends Deck
  {
      public static final String FACES[] = {"ZERO","Ace","Two","Three","Four",
              "Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
     public static final String SUITS[] = {"ZERO", "Spades", "Clubs", "Hearts", "Diamonds"};
  
      private int suit;
      private int face;
  
  
      public Card( int f, int s)
      {
          suit = s;
          face = f;
      }
  
  
      public void setFace( int f)
      {
          face = f;
      }
  
      public void setSuit( int s)
      {
          suit = s;
      }
  
  
      public int getSuit()
      {
          return suit;
      }
  
      public int getFace()
      {
          return face;
      }
  
  
      public String toString()
      {
          return FACES[face] + " of " + SUITS[suit];
      }
   }
  </code></pre>
  
  <p>BlackJackCard class:</p>
  
  <pre><code>public class BlackJackCard extends Card
  {
     private int value;
     int handVal, dealerHandVal;
     int val;
      public BlackJackCard(int f, int s)
     {
        super(f,s);
     }
  
      public int getVal()
     {
        if(getFace() == 1)
        {
           if(val + 11 &gt; 21)
           {
              value = 1;
           }
           else
           {
              value = 11;
           }
        }
        if(getFace() &gt; 1 &amp;&amp; getFace() &lt; 10)
        {
           value = getFace();
        }
        if(getFace() &gt; 10)
        {
           value = 10;
        }
        return value;
     }
  
     public String toString()
     {
        return FACES[getFace()] + " of " + SUITS[getSuit()]+ " ";
     }
  }
  </code></pre>
  
  <p>Game class:</p>
  
  <pre><code>import static java.lang.System.*;
  import java.util.Scanner;
  import java.util.Arrays;
  
  public class Game
  {
     Scanner keyboard = new Scanner(System.in);
     Deck deck = new Deck();
     public int money, bet;
     int[] card = new int[2];
     int[][] playerHand = new int[10][2];
     int[][] dealerHand = new int[10][2];
     int handPlace;
     int pHandVal;
     int dHandVal;
     boolean bust;
     boolean dBust;
  
  
  
     public void startGame()
     {
        out.println("Hello! Welcome to the Compsci Casino!");
        out.println("We have a game of Blackjack prepared for you right here.");
        out.println("It seems you've brought in $1000 in chips. You may use that to bet on your games.");
        out.println("Here is your table, good luck!");
        money = 1000;
        out.println("\n\n");
        do{
           startRound();
        }while(money &gt; 0);
        out.println("Well, it looks like you're broke. Come back when you've got some money to bet.");
     }
  
  
  
  
     public void startRound()
     {
        out.println("Alright, before I deal anything, you gotta bet some of your chips.");
        bet();
        deal();
        game();
     }
  
  
  
  
     public void printCards()
     {
        out.println("Dealer's card : " + getCardName(dealerHand[0][0], dealerHand[0][1]) + "\n");
        out.println("Your hand : ");
        for(int i = 0; i &lt; 10; i++)
        {
           if(playerHand[i][0] != 0)
           {
              out.println(getCardName(playerHand[i][0], playerHand[i][1]));
  
           }
        }
        out.println("");
  
     }
  
  
  
  
     public void game()
     {
           int c;
           do{
           printCards();
           c = choice();
           if(c == 1)
           {
              handPlace = 0;
              for(int i = 0; i &lt; 10; i++)
              {
                 if(playerHand[i][0] != 0)
                 {
                    handPlace += 1;               
                 }
              }
              card = deck.getCard();
              playerHand[handPlace][0] = card[0];
              playerHand[handPlace][1] = card[1];
              pHandVal += getHandVal(playerHand[handPlace][0], playerHand[handPlace][1]);
              if(checkBust(pHandVal) == true)
              {
                 out.println("you busted" + "\n");
              }
           }
           else if(c == 2)
           {
              do{
                 if(dHandVal &lt;= pHandVal)
                 {
                    dealerPlay();
                 }
              }while(checkBust(dHandVal) != true);
           }
           else if(c == 3)
           {
              money -= bet;
              bet = bet*2;
           }
           bust = checkBust(pHandVal);
           dBust = checkBust(dHandVal);
  
        }while(c != 2 &amp;&amp; bust != true);
  
        printDealerHand();
        if(dBust == true)
        {
           out.println("Dealer busts, you win!");
           money += bet*2;
        }
        else if(dBust != true)
        {
           if(bust != true &amp;&amp; pHandVal &gt; dHandVal)
           {
              out.print("you win!");
              money += bet*2;
           }
        }
        else if(bust == true)
        {
           out.println("you busted" + "\n");
        }
        else if(dHandVal &gt; pHandVal)
        {
           out.println("Dealer wins");
        }
     }
  
  
  
     public void printDealerHand()
     {
        out.println("Dealer's cards : " + "\n");
        for(int i = 0; i &lt; 10; i++)
        {
           if(dealerHand[i][0] != 0)
           {
              out.println(getCardName(dealerHand[i][0], dealerHand[i][1]));
  
           }
        }
        out.println("Your hand : ");
        for(int i = 0; i &lt; 10; i++)
        {
           if(playerHand[i][0] != 0)
           {
              out.println(getCardName(playerHand[i][0], playerHand[i][1]));
  
           }
        }
        out.println("");
  
     }
  
  
  
  
     public int getHandVal(int f, int s)
     {
        BlackJackCard bjc = new BlackJackCard(f, s);
        int value = bjc.getVal();
        return value;
     }
  
  
  
  
     public boolean checkBust(int val)
     {
        if(val &gt; 21)
        {
           return true;
        }
        return false;
     }
  
  
  
  
     public void dealerPlay()
     {
         handPlace = 0;
        for(int i = 0; i &lt; 10; i++)
         {
            if(dealerHand[i][0] != 0)
           {
             handPlace += 1;               
           }
       }
       card = deck.getCard();
       dealerHand[handPlace][0] = card[0];
       dealerHand[handPlace][1] = card[1];
       dHandVal += getHandVal(dealerHand[handPlace][0], dealerHand[handPlace][1]);
     }
  
  
  
  
     public String getCardName(int f, int s)
     {
        BlackJackCard blackJackCard = new BlackJackCard(f, s);
        return blackJackCard.toString();
     }
  
  
  
  
     public void bet()
     {
        bet = 0;
        do{
           out.println("you have " + money + " dollars left." + "\n");
           out.println("How much will you bet?");
           out.print("Amount :: ");
           bet = keyboard.nextInt();
           if(bet == 0)
           {
              out.println("It aint free to play here, you cant just bet nothing.");
           }
        }while(bet == 0);
        money = money - bet;
        out.println("\n");
     }
  
  
  
  
     public int choice()
     {
        int choice = 0;
        do{
        out.println("What will you do?");
        out.println("1 - Hit");
        out.println("2 - Stand");
        out.println("3 - Double");
        choice = keyboard.nextInt();
  
           if(choice == 1|| choice == 2|| choice == 3)
           {
              return choice;
           }
        }while(choice != 1 || choice != 2 || choice != 3);
        return 1;
     }
  
  
  
  
     public void resetHands()
     {
        pHandVal = 0;
        playerHand[0][0] = 0;
        playerHand[0][1] = 0;
        playerHand[1][0] = 0;
        playerHand[1][1] = 0;
        playerHand[2][0] = 0;
        playerHand[2][1] = 0;
        playerHand[3][0] = 0;
        playerHand[3][1] = 0;
        playerHand[4][0] = 0;
        playerHand[4][1] = 0;
        playerHand[5][0] = 0;
        playerHand[5][1] = 0;
        playerHand[6][0] = 0;
        playerHand[6][1] = 0;
        playerHand[7][0] = 0;
        playerHand[7][1] = 0;
        playerHand[8][0] = 0;
        playerHand[8][1] = 0;
        playerHand[9][0] = 0;
        playerHand[9][1] = 0;
        dHandVal = 0;
        dealerHand[0][0] = 0;
        dealerHand[0][1] = 0;
        dealerHand[1][0] = 0;
        dealerHand[1][1] = 0;
        dealerHand[2][0] = 0;
        dealerHand[2][1] = 0;
        dealerHand[3][0] = 0;
        dealerHand[3][1] = 0;
        dealerHand[4][0] = 0;
        dealerHand[4][1] = 0;
        dealerHand[5][0] = 0;
        dealerHand[5][1] = 0;
        dealerHand[6][0] = 0;
        dealerHand[6][1] = 0;
        dealerHand[7][0] = 0;
        dealerHand[7][1] = 0;
        dealerHand[8][0] = 0;
        dealerHand[8][1] = 0;
        dealerHand[9][0] = 0;
        dealerHand[9][1] = 0;
  
     }
  
  
  
  
     public void deal()
     {
        resetHands();
        card = deck.getCard();
        playerHand[0][0] = card[0];
        playerHand[0][1] = card[1];
        card = deck.getCard();
        playerHand[1][0] = card[0];
        playerHand[1][1] = card[1];
        pHandVal = getHandVal(playerHand[0][0], playerHand[0][1]);
        pHandVal += getHandVal(playerHand[1][0], playerHand[1][1]);
        card = deck.getCard();
        dealerHand[0][0] = card[0];
        dealerHand[0][1] = card[1];
        card = deck.getCard();
        dealerHand[1][0] = card[0];
        dealerHand[1][1] = card[1];
        dHandVal = getHandVal(dealerHand[0][0], dealerHand[0][1]);
        dHandVal += getHandVal(dealerHand[1][0], dealerHand[1][1]);
  
     }
  
  
  
  }
  </code></pre>
  
  <p>and a random number generator class:</p>
  
  <pre><code>public class Rndm
  {   
     public static double d(double low, double high) 
     { 
        double r = Math.random()*(high-low)+low; 
        return r;
     }
  
     public static int i(int low, int high) 
     { 
        double r = Math.random()*(high-low+1)+low;  
        return (int)r;    
     }
  }
  </code></pre>
  
  <p>My problem seems to be with the choice() method in the Game class. Every now and then, when it's called, it will ignore my input and look like it goes into an infinite loop, but when i look in a debugger, it just shows that the scanner is just ignoring my input.</p>
  
  <p>Again, i'm sorry there is so much code, but nobody can figure this out and i was wondering if anyone can help.</p>