// string contains numbers
String str = "The price of the book is $49";
// extract digits only from strings
String numberOnly = str.replaceAll("[^0-9]", "");
// print the digitts
System.out.println(numberOnly);
int num = 5542;
String number = String.valueOf(num);
for(int i = 0; i < number.length(); i++) {
int j = Character.digit(number.charAt(i), 10);
System.out.println("digit: " + j);
}