1 //factorial of 42 intJC = 4;//define a variable to represent the value to be computed3 LongJD = 1;//define the factorial of the final output4 5 for(inti = 1; I <= jc;i++)//define the Loop plus one, which is calculated from the beginning until the value entered6 {7JD = JD * I;//begins multiplication and continuously assigns the product of the previous number to the factorial8 }9System.out.println ("Factorial is:" +JD);//output factorialTen One
addition form of factorial calculation
1 //factorial of 42 intJC = 4;//define a variable to represent the value to be computed3 LongJD = 1;//define the factorial of the final output4 5 for(inti = JC; i > 1; i--)//directly defined in the calculated value, continuously minus one6 {7JD = JD * I;//The multiplication operation is performed, and the factorial operation of the high-level is continuously calculated to a value of8 }9System.out.println ("Factorial is:" +JD);//output factorialTen One
the subtraction form of factorial calculation
1 intJQ = 4;//define the number to be computed and assign a value2 intJW = 1;//define numeric factorial3 Doublesum = 0;//define the factorial of a number and4 5 for(inti = 1; I <= jq;i++)//loops, calculating factorial from the start6 7 {8 9JW = JW * i;//calculate factorialTen Onesum = JW +sum;//calculate factorial and A - } -System.out.println ("Factorial and for:" +sum);//output factorial and
calculation of factorial and
1 intJQ = 2;//define the number to be computed and assign a value2 DoubleJW = 1;//defines the factorial value because the factorial value is reciprocal, so the double type is used to assign the value3 Doublesum = 0;//defines the factorial and, because factorial and is reciprocal, so the double type is used to assign the value4 Doublei = 1;//define an intermediate variable to facilitate the conversion of factorial values to reciprocal forms5 6 while(JW <=JQ)7 {8 9 //• This trip has a question · //jw++; Ten //Add one here, JW will directly add 1, after output, will run more than once calculation, this is my humble opinion, please the Great God advice One Ai = i *JW; -i = 1/i; -jw++;//from the outset, add a the -sum = sum +i; - } -System.out.println ("Factorial and for:" +sum); +
the inverse factorial and
The For loop calculates the factorial, factorial, and its inverse factorial of a number and