title: Java error message java.lang.StringIndexOutOfBoundsException: String index out of range: 0
body: <p>here is my program</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Random;
  
  public class Project3
  {
      public static void main(String[] args)
      {
  
          int low;
          int high;
          int answer;
          int guess;
          int numGuess = 0;
          int x;
          int y;
  
         char repeat; // this will hold y or n 
         String input; //holds input to perform entire loop
  
  
          System.out.println( "Hello and welcome to Guess That Number!");
  
              Scanner keyboard = new Scanner(System.in);
  
          System.out.println("For starters you get to pick the range the number falls in!" +
                              " HOW EXCITING!");
  
  
          System.out.println( "Now what would you like the lowest possible number to be?");
                        low = keyboard.nextInt();
  
          System.out.println( "and the highest?");
                        high = keyboard.nextInt();
   do  
    {    Random randomNumber = new Random();
  
          answer = randomNumber.nextInt();
         while (answer &lt; low || answer &gt; high)
         { 
          answer = randomNumber.nextInt();
      }
  
  
  
         guess = -1;
  
         while(guess != answer)
         {
  
             System.out.println("What is your guess?");
            System.out.println("Don't forget has to be in between "+ low + " and " + high);
  
                     guess = keyboard.nextInt();
  
                     numGuess = (numGuess + 1);
  
                  if (guess &lt; answer)
                  {
                      System.out.println("TOO LOW!");
  
                  }
  
                  else if (guess &gt; answer)
                  {
                      System.out.println("TOO HIGH!");
  
  
  
                  }
  
  
              }
  
  
  
  
  
         System.out.println("YOU GOT IT WOOOO!");
         System.out.println("The number was " + answer);
         System.out.println("Nice it only took " + numGuess + "!");
  
         for ( x = 1; x &lt;= numGuess; x++)
  
        {
  
            for ( y = 1; y &lt;= answer; y++)
  
              {
                  System.out.print("*");
              }
  
              System.out.println();
  
  
  
        }
  
  
        System.out.println("\nWould you like to play again? \n" +        // this is to loop the entire game
                        "Enter Y for yes or N for no. \n");
  
                        input = keyboard.nextLine();
                        repeat = input.charAt(0);
  
    } while (repeat == 'Y' || repeat == 'y');
  
      if (repeat == 'n' || repeat == 'N')             
      {
  
      System.out.println("\nThanks for playing! \n");
  
     }
  }
  }
  </code></pre>
  
  <p>when i try and run it it gives me this error message </p>
  
  <p>java.lang.StringIndexOutOfBoundsException: String index out of range: 0
   at java.lang.String.charAt(String.java:687)</p>
  
  <p>how do i fix it so the program loops correctly?!?</p>