fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. System.out.println(countInitialZeros("0005606"));
  10. System.out.println(countInitialZeros("005606"));
  11. System.out.println(countInitialZeros("05606"));
  12. System.out.println(countInitialZeros("5606"));
  13. System.out.println(countInitialZeros("0000"));
  14. }
  15. public static int countInitialZeros(String haystack) {
  16. for (int i=0; i < haystack.length(); i++)
  17. {
  18. if (haystack.charAt(i) != '0') {
  19. return i;
  20. }
  21. }
  22. return haystack.length();
  23. }
  24. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
3
2
1
0
4