Q:

Create a java program that prompt the user for a positive number and then displays each digit in reverse order on a separate line

import java.util.Scanner;

class Digitsdisplay {
public static void main(String args[]){
    Scanner input = new Scanner(System.in);

    System.out.println("Please enter a value: ");

    int value = input.nextInt();
    int total  = 0;
    String digit = "" + value;

    System.out.print("");

    for (int i = 0; i < digit.length(); i++) {
       int myInt = Integer.parseInt(digit.substring(i, i + 1));
       System.out.println(myInt);
       total += myInt;
    }

}
}

output:
Please enter a value: 
789
7
8
9
How do I reverse the output? For example, when I enter the number 123, it would display 321 with each digit on a new line.

A:

Simply reverse the string before looping through it
digit = new StringBuilder(digit).reverse().toString();

