帮做一道JAVA编的求n!的阶层,用do while语句,谢谢各位
解决方案 »
- java垃圾回收问题
- 有一字符串"dsfads=sdfdd",我想分别去"=号"左边和"=号"右边的字符请问有什么函数啊?
- 十万火急,请大家过来帮我看看着个程序吧?
- 如 何 使 一 个 SWING 组 件 透 明。
- 求一个String的处理方法
- 如何将文件以流的形式保存到oracle数据库中
- 如何引用这样的类?!
- 请教一个问题
- JDK安装在WINXP下,怎么配置环境变量啊??
- 我的电脑最近不知是中了病毒还是怎么了,jbuilder6与jbuilder7都无法安装
- 200分给一人,JAVA关于SQL2000 exec sp_cursorfetch 180150002, 16, ****, 1的问题
- finally block does not complete normally
long rtn = 1;
do{
rtn *= n;
}while(--n > 0);
return rtn;
}
System.out.println(" ForTest----- " + ForTest(5));
} public static int WhileTest(int m) { if (m == 0 || m == 1) {
return 1;
} int i = 1;
int s = 1;
while (i <= m) {
s *= i;
i++;
}
return s;
} public static int DoWhileTest(int m) { if (m == 0 || m == 1) {
return 1;
} int i = 1;
int s = 1;
do {
s *= i;
i++;
} while (i <= m);
return s;
} public static int ForTest(int m) {
if (m == 0 || m == 1) {
return 1;
}
int s= 1;
for(int i=1;i<=m;i++){
s*=i;
}
return s;
}
public static int IfTest(int m) { if (m == 0 || m == 1) {
return 1;
} else {
return m * IfTest(m - 1);
} }}
运行结果:
if----- 120
while----- 120
dowhile----- 120
ForTest----- 120