title: Print each digit of a number on a new line in Java
body: <p>I have the following code written with the purpose of the program is for the user to input a number i.e. 123 and the program will output it as 1 2 3 vertically. No matter what I do, my program does it as 3 2 1. I need to use a loop in this program and I can't seem to figure it out.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class DigitsDisplay {
      public static Scanner console = new Scanner(System.in);
  
      public static void main(String[] args) {
          int a = getInt("Give a non-negative integer: ");
          double backwards = 0;
          int reverse;
          int numOfDigits = numOfDigits(a);
          double place = Math.pow(10, numOfDigits);
  
          while (a != 0) {
              reverse = a % 10;
              backwards = backwards + place * reverse;
              System.out.println(reverse);
              a = a / 10;
          }
      }
  
      public static int getInt(String prompt) {
          int input;
  
          System.out.print(prompt);
          input = console.nextInt();
  
          return input;
      }
  
      public static int numOfDigits(int a) {
          int numOfD = (int)(Math.log10(a)) + 1;
  
          return numOfD;
      }
  
  }
  </code></pre>