For that you can use the modulo operator.
public class Main {
/** http://stackoverflow.com/q/36053971/6077352 */
public static void main(String[] args) {
int input = 123456789;
while (input > 0) {
if (input % 2 == 0) {
System.out.println(input % 10 + " is even");
} else {
System.out.println(input % 10 + " is odd");
}
input = input / 10;
}
}
}
Example output:
9 is odd
8 is even
7 is odd
6 is even
5 is odd
4 is even
3 is odd
2 is even
1 is odd
solved How to list even and odd digits from integer inputs