info@meritcampus.com    +91-85006-22255
...
`

Write a program to calculate the total number of permutations possible.

Input (Integer, Integer) Output (Integer)
13P3 1716
6P2 30
8P1 8
10P0 1
5P5 120
0P5 null

``` class NumberOfPermutations {     public static void main(String s[])    {        System.out.println("Total number of permutations of 13P3 : " + numberOfPermutations(13, 3));    }     public static Integer numberOfPermutations(int total, int choiceCount) { ```
```     } } ```
Topic:

### User comments below.All of them might not be correct.

As per the question we need to find out the permutations of nPr... so the formula is n!/(n-r)!... or we can use a loop to iterate 'r' times by decrementing n for every iteration... like 6P2 = (6)(6-1) = 6 * 5 = 30... use a loop with condition i=0;i<r;i++ and decrement n for every iteration...

Posted by Gopinath Manchikanti    2015-02-17 06:18:18

To find the permutations we have to use the following following formulare:
nPr = n! / (n-r)!

--We have to define one function named fact(int n) which accepts integer number and calculates the factorial of that number.one FOR LOOP should be used as follows:

------->
for(int i=1;i<=n;i++)
{
f=f*i;
}
return f;

--After that in numberOfPermutations() function,we have to calculate npr as follows:

---->int npr=fact(total)/fact(total-choiceCount)

Then we have to convert this primitive int to Iteger object by using wrapper class method as follows:

---->Integer op=new Integer(npr)

--Then,we have to return that op object by return statement.

---> return op;

Posted by Mânïshå Mùlchåndânï    2015-02-17 09:52:43

This dose is now closed and the winners are Gopinath Manchikanti,  for 'First Correct Comment', Mânïshå Mùlchåndânï,  for 'Second Correct Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-02-18 03:52:27