//可以输入任何一个数,回车退出 import java.io.* ; class jiecheng{public static void main(String args[]) throws IOException{ long j=1; int i=0; char reads; String s=""; int number=0; system.out.println("please input a number <65536"); while((i=System.in.read())!='\n'){
class jiecheng{public static void main(String args[]) throws IOException{
long j=1;
int i;
char reads;
String s="";
while((i=System.in.read())!=-1){
reads=(char)i;
s+=reads;
}while(i!=1)
{j*=i;
i--;
} System.out.print(j);
}
}
//实施这个,输入完后,回车,然后ctrl+z,回车
其次任何尝试用int/long作n!的尝试都将导致失败,你现在只有一位数的阶乘,还不会出问题,但是一旦你算到21,22,你就会得到一个负数,原因就是越界了,因此需要使用BigDecimal
import java.io.* ;
class jiecheng{public static void main(String args[]) throws IOException{
long j=1;
int i=0;
char reads;
String s="";
int number=0;
system.out.println("please input a number <65536");
while((i=System.in.read())!='\n'){
number=number*10+(int)i;
}while(number!=1)
{
j*=number;
number--;
} System.out.print(j);
}
}
must controll the format
你的代码肯定越界的啊,稍微大一点的数就死的。程序里还有错误,不知道你帖之前自己测过没有