角谷猜想 请输入一个自然数java
答案:2 悬赏:80
解决时间 2021-03-21 10:27
- 提问者网友:长安小才冯
- 2021-03-20 23:56
请输入一个自然数,然后把这个数,若为奇数则乘三加一,若为偶数则除以二。循环输出最后结果。麻烦用JAVA 编写这个程序。。。。。
最佳答案
- 二级知识专家网友:许你一世温柔
- 2021-03-21 00:51
import java.io.*;
public class Jiegu{
public static void main(String args[]) throws IOException{
int c;
c=(int)System.in.read();
System.out.print(dgui(c));
}
static int dgui(int c){
if(c==1)
return 1;
else if (c%2==0)
return dgui(c/2);
else
return 3*c+1;
}
}
}
public class Jiegu{
public static void main(String args[]) throws IOException{
int c;
c=(int)System.in.read();
System.out.print(dgui(c));
}
static int dgui(int c){
if(c==1)
return 1;
else if (c%2==0)
return dgui(c/2);
else
return 3*c+1;
}
}
}
全部回答
- 1楼网友:佛说妍妍很渣
- 2021-03-21 01:50
设四个自然数为n—1、n、n+1、n+2 证明(n-1)x(n)x(n+1)x(n+2)+1 否是一个平方数即可
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯