Advertisement
Codex

Get numbers from String

Jul 27th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. /*find numbers from the given string.
  2. for example if string is"face45face56"
  3. the output must be 4556*/
  4. import java.util.Scanner;
  5. class StringFun
  6. {
  7. public static void main(String args[])
  8. {
  9. Scanner sc=new Scanner(System.in);
  10. String s=sc.nextLine();
  11. int i;
  12. String s2="";
  13. char ch;
  14. for(i=0;i<s.length();i++)
  15. {
  16. ch=s.charAt(i);
  17. if(Character.isDigit(ch))
  18. s2=s2+ch;
  19. }
  20. int num=Integer.parseInt(s2);
  21. System.out.println(s2);
  22. //now do anything with num
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement