The For loop calculates the factorial, factorial, and its inverse factorial of a number and

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.