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 java.lang.Exception
  11. {
  12. String string = "123hh h3ll0 w0rld";
  13.  
  14. int count = 0;
  15. boolean inDigits = false;
  16. for (int i = 0; i < string.length(); i++)
  17. {
  18. char c = string.charAt(i);
  19.  
  20. if (Character.isDigit(c)) {
  21. if (!inDigits) count++;
  22. inDigits = true;
  23. } else {
  24. inDigits = false;
  25. }
  26. }
  27.  
  28. System.out.println(count);
  29.  
  30. }
  31. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
4