title: How to read each individual digit of a number in Java
body: <p>I am trying to run a program that outputs the sum of every digit of an entered in integer. How would I go about reading the number and outputting each digit?</p>
  
  <p>Example: Input is 4053 the output would be "4+0+5+3 = 12".</p>
  
  <pre><code>import java.util.Scanner; 
  
  public class Digits{
      public static void main(String args[]) {
      //Scans in integer   
          Scanner stdin = new Scanner(System.in);
          System.out.println("Enter in a number: ");
          int number = stdin.nextInt();
  
          //Set sum to zero for reference
          int sum = 0;
          int num = number; //Set num equal to number as reference
  
          //reads each digit of the scanned number and individually adds them                                  together
          //as it goes through the digits, keep dividing by 10 until its 0.
          while (num &gt; 0) {
              int lastDigit = num % 10; 
              sum = sum + lastDigit;
              num = num/10;
          }
      }
  }
  </code></pre>
  
  <p>That is the code I used for calculating the sum of the individual digits, now I just need help with outputting the individual digits. Any tips and tricks would be much appreciated.</p>