第一题:

public class Hailstone {

   /* public static int Hailstone(int x){
        arr[0]=x;
    }*/
    public  static int hailstoneLength(int n){
        for(int i=1;;i++) {
            if (n == 1) {
                return i;
            } else if (n % 2 == 0) {
                n /= 2;
            } else {
                n = n * 3 + 1;
            }
        }
    }
    public static boolean isLongSeq(int n){
        if(hailstoneLength(n)>n) return true;
        else return false;
    }
    public  static double propLong(int n){
        int s=0;
        for(int i=1;i<=n;i++){
            if(isLongSeq(i)==true) s++;
        }
        return (s*1.0)/n;
    }
}
Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐