public class Test1{ public static void main(String[] args){ int i=1; int A=1; while(i<=100){ A=i*A; i++; } System.out.println("1*2*3*4*5*6*...*100="+A); }}
//超过了整型的最大范围、。于是就是0
import java.math.*;
class Test1 {
public static void main(String[] args) {
int i = 1;
BigInteger A = BigInteger.ONE;
while (i <= 100) {
A = BigInteger.valueOf(i).multiply(A);
i++;
}
System.out.println("1*2*3*4*5*6*...*100=" + A);
}
}
import java.math.*;
class Test1 {
public static void main(String[] args) {
int i = 1;
BigInteger A = BigInteger.ONE;
while (i <= 100) {
A = BigInteger.valueOf(i).multiply(A);
i++;
}
System.out.println("1*2*3*4*5*6*...*100=" + A);
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-01-03
因为数据溢出了,你用int保存存储结果,int可存储的数值范围最大也就21亿多一点,你这么连乘法,没几次就超过了本回答被提问者采纳