How do I display the individual integers from the scanner input stream for example if the user enters 500 I would like to display it as 5, 0, 0. Here is the code guys
import java.util.Scanner;
public class Digit {
public static void main(String[] args) {
int number, i = 0, num, digits;
int[] digit;
Scanner input = new Scanner(System.in);
System.out.print("Please enter the digit: ");
try{
number = input.nextInt();
num = number;
digits = 0;
while(num > 0){
digits = num % 10;
digit = new int[]{digits};
num = num / 10;
i++;
}
System.out.println("The length of the given: "+number+ " is: "+i);
System.out.println("The Digits are: "+digit+" ,");
}
catch(Exception exception){
exception.printStackTrace();
}
finally{
input.close();
}
}
}
But when I execute this code I am getting an error
$ javac Digit.java
Digit.java:20: error: variable digit might not have been initialized
System.out.println("The Digits are: "+digit+" ,");
^
1 error
How I fix this ?