Answers for "java separate the numbers from string"

1

java separate the numbers from string

// 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);
Posted by: Guest on October-25-2021
2

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;

}

}
Posted by: Guest on January-18-2021
0

split number java

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);
}
Posted by: Guest on August-27-2021

Code answers related to "java separate the numbers from string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language