fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) throws Exception
  11. {
  12.  
  13. String str;
  14. String numbers;
  15.  
  16. Scanner SC=new Scanner(System.in);
  17.  
  18. System.out.print("Enter string that contains numbers: ");
  19. str=SC.nextLine();
  20.  
  21. //extracting string
  22. numbers=str.replaceAll("[^0-9. ]", "");
  23.  
  24. System.out.println("Numbers are: " + numbers);
  25. }
  26. }
Success #stdin #stdout 0.08s 29420KB
stdin
r ( 4.5, 1.0 ) 10.5 7 
stdout
Enter string that contains numbers: Numbers are:   4.5 1.0  10.5 7