title: How do I split an integer that a user entered into an array of digits in Java?
body: <p>I am trying to take a 4 digit number a user enters and split it into an array of digits.
  So for example a user enters the number &quot;2000&quot; and it is split into [2,0,0,0].</p>
  <p>I have tried this, but it does not work.</p>
  <pre><code>Scanner myObj = new Scanner (System.in);
          System.out.println(&quot;Enter 4 numbers&quot;);
  
          int userNumbers = myObj.nextInt();
          
          int[] array = new int [4];
          
            array[0] = userNumbers[0];
            array[1] = userNumbers[1];
            array[2] = userNumbers[2];
            array[3] = userNumbers[3]; 
  </code></pre>
  <p>I have also tried which works nicely but it is converting the numbers to strings in the array. I need an array of integers.</p>
  <pre><code>Scanner myObj = new Scanner (System.in);
          System.out.println(&quot;Enter 4 numbers&quot;);
  
          int userNumbers = myObj.nextInt();
         
          String[] digits = Integer.toString(userNumbers).split(&quot;&quot;);
          System.out.println(Arrays.toString(digits));
  </code></pre>
  <p>I am literally just beginning Java so I am aware this is quite basic stuff. I just need a point in the right direction. Thanks a lot!</p>