Problems Scanner in Java
<p>I was having difficculties when trying to read from a JOPtionPane input dialog using a Scanner object (text below)</p>

<pre><code>int array[] = new int[6];
for (int i=0; i&lt;6; i++)
    { 
        Scanner sc = new Scanner(System.in);
        JOptionPane.showInputDialog("Enter a number to fill the array: ");
        array[i]=sc.nextInt(System.in);
    }
</code></pre>

<p>Difficulties got solved when changed code like follows:</p>

<pre><code>String st;
int array[] = new int[6];
for (int i=0; i&lt;6; i++)
    { 
        st= JOptionPane.showInputDialog("Enter a number to fill the array: ");
        array[i] = Integer.parseInt(st);
    }
</code></pre>

<p>I would like to know why I can't fill the array using a Scanner class object :/</p>
