How can I separate the digits of an int number in Java

718    Asked by AudreyBerry in Salesforce , Asked on Apr 16, 2021

If I have a number 2500, I want the output to be: 2, 5, 0, 0. How can I separate the numbers into digits? 

We can easily split integers into digits java.

public static void main(String[] args) {
int num=1020; // int number
while (num > 0) {
    System.out.println( num );
    num = num / 10;
}
}


Your Answer

Interviews

Parent Categories