private static int chain(int n){
int count = 0;
while(n > 1){
if(n % 2 == 0){
count++; //the value is not stored
return chain(n/2);
}
count++; //same thing
return chain(3*n+1);
}
return count; //prints the initial value (0)
}
}
我需要打印出链式方法重复出现的次数。