To do this, you will use the % (mod) operator.

int number; // = some int

while (number > 0) {
    print( number % 10);
    number = number / 10;
}

The mod operator will give you the remainder of doing int division on a number.

So,

10012 % 10 = 2

Because:

10012 / 10 = 1001, remainder 2

Note: As Paul noted, this will give you the numbers in reverse order. You will need to push them onto a stack and pop them off in reverse order.

Code to print the numbers in the correct order:

int number; // = and int
LinkedList<Integer> stack = new LinkedList<Integer>();
while (number > 0) {
    stack.push( number % 10 );
    number = number / 10;
}

while (!stack.isEmpty()) {
    print(stack.pop());
}
Answer from jjnguy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-extract-digits-from-a-given-integer
Java Program to Extract Digits from A Given Integer - GeeksforGeeks
July 23, 2025 - Convert the input into string data. Traverse through the string and print the character at each position that is the digits of the number. Below is the implementation of the above approach: ... // Java program to Extract Digits from A Given ...
🌐
Medium
medium.com › @pyjavahub › how-do-you-extract-digits-from-a-number-5eb18b31f767
How do you extract digits from a number? | by Pyjava hub | Medium
August 29, 2025 - How do you extract digits from a number? Logic Read the number. Use % 10 to get the last digit. Print/store it. Divide the number by 10 (// in Python, / in Java for int). Repeat until number becomes …
🌐
TutorialsPoint
tutorialspoint.com › article › java-program-to-extract-digits-from-a-given-integer
Java Program to Extract Digits from A Given Integer
May 31, 2024 - We covered two different scenarios: ... modulus approach, we learned how to extract digits by repeatedly dividing the number by 10 and using the remainder as the digit....
🌐
KnowledgeBoat
knowledgeboat.com › learn › icse-computer-applications-bluej-class-10 › lecture › ml4Jm › java-digit-extract
Solved Example: Extracting Digits of a Number | Video Tutorials for ICSE Computer Applications with BlueJ | KnowledgeBoat
You got your digit, now if you perform integer division on the number by 10, it will truncate the number by removing the digit you just extracted. You need to repeat these two steps till the number becomes zero to extract all digits of the number. Let’s apply these steps on 357 and see if we can extract 3,5 and 7 from it.
Published: September 20, 2019
🌐
Sanfoundry
sanfoundry.com › java-program-extract-digits-given-integer
Java Program to Extract Digits from a Given Number - Sanfoundry
May 23, 2022 - Here is the source code of the Java Program to Extract Digits from A Given Integer. The Java program is successfully compiled and run on a Windows system. The program output is also shown below. ... $ javac Extract_Digits.java $ java Extract_Digits Enter any number:5678 Digits at position 4:8 Digits at position 3:7 Digits at position 2:6 Digits at position 1:5
🌐
Sololearn
sololearn.com › en › Discuss › 133085 › how-to-extract-digits-in-java
How to extract digits in java. | Sololearn: Learn to code for FREE!
if there is a 5 digit number how to extract each digit. java · 18th Dec 2016, 2:53 PM · mamata sethy · 6 Answers · Answer · + 5 · int number = 12345; for(int i = 0; i<5; i++){ System.out.println(number); number /= 10; } output: 5 4 3 2 1 demo: https://code.sololearn.com/cMtAc900HAHw ·
🌐
CompleteEra
completeera.com › how-to-extract-each-digit-of-a-number-in-java-simple-code
How to Extract Each Digit of a Number in Java: Simple Code - CompleteEra
May 5, 2026 - ... public static void extractDigitsString(int number) { String numStr = Integer.toString(Math.abs(number)); // Handle negatives for (int i = 0; i < numStr.length(); i++) { char digitChar = numStr.charAt(i); int digit = Character.getNumericValue(digitChar); System.out.println("Digit: " + digit); } }
Find elsewhere
🌐
IncludeHelp
includehelp.com › java-programs › extract-digits-numbers-from-string.aspx
Java program to extract digits/ numbers from the string
//Java program to extract ....print("Enter string that contains numbers: "); str=SC.nextLine(); //extracting string numbers=str.replaceAll("[^0-9]", ""); System.out.println("Numbers are: " + numbers); } }...
🌐
sqlpey
sqlpey.com › java › java-methods-extract-integer-digits
Various Java Methods to Extract Individual Digits from an Integer
November 4, 2025 - void extractDigitsByDivisor(int number) { if (number < 0) return; // Determine the highest power of 10 less than or equal to the number int divisor = 1; // This loop determines the magnitude (e.g., 1000 for 1234) while (number / divisor >= 10) { divisor *= 10; } System.out.print("Digits (By ...
🌐
CodingTechRoom
codingtechroom.com › tutorial › java-java-integer-individual-digits
Extracting Individual Digits from an Integer in Java - CodingTechRoom
... You can extract the individual digits of an integer by using mathematical operations such as modulus and division. The modulus operation can help us retrieve the last digit, while integer division can reduce the number for further processing.
🌐
Iditect
iditect.com › program-example › string--extracting-digits-of-int-in-java.html
string - Extracting digits of int in Java
To extract individual digits from an integer in Java, you can convert the integer to a string and then iterate over each character of the string to extract the digits. Alternatively, you can use mathematical operations to extract digits one by one without converting to a string.
🌐
iCert Global
icertglobal.com › home › community › what is the most efficient way to separate and print individual digits of an integer in java?
How to Separate Digits of a Number in Java Using Math
The most efficient way to separate digits without the overhead of object creation is using the modulo (%) and division (/) operators. By using number % 10, you extract the last digit, and by using number / 10, you remove that last digit from ...
🌐
CodingTechRoom
codingtechroom.com › question › extract-digits-integer-java
How to Extract Digits from an Integer in Java? - CodingTechRoom
int number = 12345; List<Integer> ... through various techniques, the most common being the use of arithmetic operations or converting the integer to a string....
🌐
Javatpoint
javatpoint.com › digit-extraction-in-java
Digit Extraction in Java - Javatpoint
Digit Extraction in Java with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Baeldung
baeldung.com › home › java › java numbers › how to split an integer number into digits in java
How to Split an Integer Number Into Digits in Java | Baeldung
January 8, 2024 - To solve this, we can use LinkedList as a stack and push() the reminder to the stack in each step: int number = THE_NUMBER; LinkedList<Integer> result = new LinkedList<>(); while (number > 0) { result.push(number % 10); number /= 10; } ...
🌐
Pressbooks
pressbooks.lib.jmu.edu › programmingpatterns › chapter › digitmanipulation
Digit Manipulation – Patterns for Beginning Programmers
May 6, 2022 - cardNumber = 412831758; accountType = cardNumber % 10; // Extract right-most 1 digit · To extract the issuing bank number you must extract the left-most three digits of a nine digit number.