“求阶程”的问题
Ancom 2004-11-15 06:17:14 做习题“求某数的阶程”时 遇到了问题。检查了很多遍程序 好象没有问题 可运行时候出现的结果确与实际答案大相径庭。
麻烦大家帮我这个初学者看看
import java.io.*;
public class jiecheng
{
public static void main(String[] args)
{
char c=0;
int m=0;
System.out.println("count zhe jiecheng of 'n' ");
System.out.println("enter the num of 'n': ");
try{
c=(char)System.in.read();
}catch(IOException e){};
m=(int)c;
factorial(m); //调用方法factorial
}
//方法 计算n的阶程
static void factorial(int n)
{
int x=n;
long y=1l;
for(;x>0;x--)
y *= x;
System.out.println(n+"!="+y);
}
}
像直接factorial(8) 这样求某个确定数的阶程又不会出错
各位帮忙检查一下,谢过