The fourth cycle i=2*5- 1=9, so 7! No, the next cycle is i=2*9- 1= 17, which is even more wrong.
2 Count me in! There is something wrong with the cycle of, only I = I * J. For example, i=3 and J = J * I =1* 3,3 in the second cycle! It should be 1×2×3.
(3) The factorial value is too large to be saved in int type, and the result can be saved in proportion in long type.
Public static void main(String[] args)
{
Length j= 1, and =1;
for(int I = 3; I<= 19; i+=2)
{
j = j *(I- 1)* I;
sum = sum+j;
system . out . println("+I+"! = "+j); //This sentence can be used to output the factorial in the middle, without comment.
}
system . out . println(" sum = "+sum ");
}
The output is as follows:
3! =6
5! = 120
7! =5040
9! =362880
1 1! =399 16800
13! =6227020800
15! = 1307674368000
17! =355687428096000
19! = 12 1645 100408832000
sum = 122002 10 177860 1647