java get digits of int code example
Example 1: how to store a 6 digit number as 6 separate integers
int number; // = some int
while (number > 0) {
print( number % 10);
number = number / 10;
}
Example 2: find number of digits in a number java
(int)Math.floor(Math.log10(Your_number_name_goes_here) + 1);
Example 3: how to separate a number into digits java
public static void main(String[] args) {
int num=1020; // int number
while (num > 0) {
System.out.println( num % 10);
num = num / 10;
}
}