DESKTOP-I6FA4UK_20200830-刘光超

1、问题

//计算字符串片段的平均长度
public class Test {
    public static void main(String[] args) {
        String s = "aaabbaaac";
        char[] c = s.toCharArray();
        int n = c[0];
        
        int a = 1;
        for(int x =0;x<c.length-1;x++) {
            if(n!=c[x+1]) {
                n=c[x+1];
                a++;
            }
        }
        double sum = (double)c.length/a;
        System.out.println(c.length+"  "+a+"  "+sum);
    }

2、吐槽

要做三个小时的无用功了

标签

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1