java编程计算机n的阶乘设n=10
来源:百度知道 编辑:UC知道 时间:2024/05/09 19:46:39
这个问题我老是觉得自己的办法不是很简洁,不知道谁能帮帮忙
public static void main(String args[]) {
int n=10;
int result=1;
for( int i=1;i<=n;i++ ){
result *= i;
}
System.out.println(result);
}
public class j{
public static void main(String []args){
int i,s=1;
for(i=1;i<=10;i++) s*=i;
System.out.println("n!="+s);
}
}
import java.io.*;
class test
{
static long cal(long n)
{
if(n == 1)
return 1;
else
return cal(n-1)*n;
}
public static void main(String args[]) throws IOException
{
System.out.print("请输入一个整数:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
System.out.println (a + "阶乘是:");
System.out.println (cal(a));
}
}
不会