title: getting an error putting digits from a file into an array (Java)
body: <p>I want to take the first 15 digits from the following and put them in an array. The issue is it inputs all the digits up until "344". This digit appears as only "34". I"m assuming this is because the count is counting invalid inputs like "xxx" as digits. I'm not sure how to resolve this.  </p>
  
  <pre><code>0
  4
  23
  566
  34
  xxx
  45
  555
  11
  34
  35
  45
  xxx
  65
  
  55
  98
  344
  54
  </code></pre>
  
  <p>This is my code (3 sections one adds the file one plays the game and one prints the results): </p>
  
  <pre><code>public class JumpIt {
  
      // Constants
      private int count = 0;
      private final int MAX_SIZE = 15;
      public int[] arr = new int[MAX_SIZE];
  
      public JumpIt(String theName) throws FileNotFoundException {
          @SuppressWarnings("resource")
          Scanner scanner = new Scanner(new File("file.txt"));
          int i=0;
          while(scanner.hasNext() &amp;&amp; count &lt; 15) {   //only need first 15 
              if (scanner.hasNextInt()) {
                  arr[i++] = scanner.nextInt();
                  count+= 1;
              }
              else {
                  String s = scanner.nextLine();
                  System.out.println(s);
              }
          }
      }
  
      int n = 0;
      public int play() throws BadInputException{             //gets size
          if(arr[0]!= 0) {
              throw new BadInputException(); 
          }
          return play(arr,0,count-1);
      }
  
      private static int play(int arr[],int first, int last) { 
          if(first &gt; (last)) {
              return 0;
          }
          else if ((first + 1)&gt;last){
              return arr[first];
          }
          else {
              if (arr[first] &lt; arr[first + 1]) {
                  return arr[first] + play(arr,first+2,last);
              }
              else {
                  return arr[first+1] + play(arr,first+2,last);
              }
          }
      }
  
      public void printGame() {
          if(count &gt; 10) {
              for(int i = 0; i &lt; 10; i++) { 
                  System.out.print(arr[i] + " ");
              }
              n = count - 10;
              for(int i = 0; i &lt; n; i++) {
                  System.out.print(arr[i] + " ");
              }
          }
          //if(count &gt; 15) {
          //  System.out.println("The file has more than 15 integers");
          //  System.out.println("Only the first 15 integers are considered");
          //}
          else {
              n = count; 
              for(int i = 0; i &lt; count;i++) {
                  System.out.print(arr[i]);
              }
          }
          System.out.println("The file has "); 
          System.out.print(count);
          System.out.println(" " + "integers.");
          }
  }
  </code></pre>
  
  <p>and this is my main: </p>
  
  <pre><code>public class Driver {
  public static void main(String[] args) throws FileNotFoundException {
      JumpIt game4 = new JumpIt("file.txt");
      game4.printGame();
      System.out.println("");
      System.out.println("play game");
      try {
              System.out.println("the cost is " + game4.play());
              System.out.println("");
      } catch (BadInputException e){
              System.out.println("bad input: the first int must be 0");
      }
  </code></pre>