title: How can I save the value of a String that is ParseInt()ed into an array?
body: <p>Basically, I need to use the <code>Integer.parseInt()</code> function to convert 10 strings into integers which will then be averaged.</p>
  <p>Also need to catch any Exceptions but I'm confused as to how to keep the program running so that when the user makes an error the array stays in the x value before the mistake was entered and keeps asking for a correct integer.</p>
  <p>Running this right now gives an error since intNum can't be made into a variable, I'm sure it has to do with how i arranged my do and try methods?</p>
  <pre><code>public static void main(String[] args) {
          
      int p=1;
      Scanner scan = new Scanner(System.in);
      int tenNums[] = new int [10];
          
      for (int x=0; x&lt;10; x++) {
              
          System.out.println(&quot;Enter number: &quot;);
          String stringNum = scan.next();
          do {
              try {
                  int intNum = Integer.parseInt(stringNum);
              }
              catch(NumberFormatException e) {
                  System.out.println(&quot;Wrong Input&quot;);
              }
              p = 2;
          } while (p == 1);
          tenNums[x] = intNum;
      }
  }
  </code></pre>