本帖最后由 java2000_net 于 2008-08-05 09:13:59 编辑

解决方案 »

  1.   


    package test;public class Main {    public static void main(String[] args) {
            String s1 = "12300000000";
            String s2 = "12301000000";
            String s3 = "12301500000";
            System.out.println(getIndex(s1));
            System.out.println(getIndex(s2));
            System.out.println(getIndex(s3));
        }    public static int getIndex(String str) {
            if (str == null) {
                return -1;
            }
            for (int i = str.length() - 1; i >= 0; i--) {
                char ch = str.charAt(i);
                if (ch != '0') {
                    return i;
                }
            }
            return -1;
        }
    }