第一题:
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; } }