解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Demo {
public static int print(int n) {
int num = 1;
while(n != 1) {
if(n % 2 == 0) {
n = n / 2;
}else {
n = 3 * n + 1;
}
num++;
}
return num;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt(),y = in.nextInt(),max,temp;
if(x>y) {
temp = x;
x = y;
y = temp;
}
max = 0;
for(int i=x;i<=y;i++) {
if(max<print(i))
max = print(i);
}
System.out.println(x+"-"+y+":"+max);
}
}
0.0分
0 人评分