There are two errors in the following JAVA program:
static void g(int i){
if(i==1){return;}
if(i%2==0){g(i/2);return;}
else {g(3*i);return;}
}
please correct them to make sure we can get the printed-out result as below:
3 10 5 16 8 4 2 1感觉题目有点奇怪,大家说说怎么改
static void g(int i){
if(i==1){return;}
if(i%2==0){g(i/2);return;}
else {g(3*i);return;}
}
please correct them to make sure we can get the printed-out result as below:
3 10 5 16 8 4 2 1感觉题目有点奇怪,大家说说怎么改
解决方案 »
- 百分请教关于event监听器的问题
- 一个关于java.lang.ClassCastException: java.lang.Class的问题
- 请教:用sdk1.5+eclipce 3.2+myeclipce 5.0+tomcat 5.5或近似工具进行环境配置
- 孙鑫《java无难事》视频刻碟邮寄优惠
- 如何装一个String变量内容下载到客户端文件
- Exception in thread "main" java.lang.NoClassDefFoundError的问题
- 有关数据流的操作,比较,给些建议,谢谢!
- 有那个大侠,提供一下做过的项目的例子让大家学习一下,或者是提几个简单的项目让大家试做一下。
- 引用Swing问题
- 如何改变JAVA程序的左上角图标?谢谢
- 求助!!!关于jsp运行环境的问题。
- 几个基础性问题,类,包,类路径
public static void main(String[] args) {
g(3);
} static void g(int i) {
System.out.println(i);
if (i == 1) {
return;
}
if (i % 2 == 0) {
g(i / 2);
return;
} else {
g(3 * i+1);
return;
}
}
}
该问题能够收敛是基于一个数学原理
System.out.print(i + " ");
if (i == 1) {
return;
}
if (i % 2 == 0) {
g(i / 2);
return;
} else {
g(3 * i + 1);
return;
}
}
public static void main(String[] args)
{
g(3);
} static void g(int i)
{
System.out.println(i);
if (i == 1)
{
return;
}
if (i % 2 == 0)
{
g(i / 2);
return;
} else
{
g(3 * i+1);
return;
}
}
}