Java program to find the permutation when the values n and r are given

Permutation refers a number of ways in which set members can be arranged or ordered in some fashion. The formula of permutation of arranging k elements out of n elements is −

nPk = n! / (n - k)!


1. Define values for n and r.
2. Calculate factorial of n and (n-r).
3. Divide factorial(n) by factorial(n-r).
4. Display result as a permutation.


import java.util.Scanner;

public class Permutation {
   static int factorial(int n) {
      int f;

      for(f = 1; n > 1; n--){
         f *= n;
      return f;
   static int npr(int n,int r) {
      return factorial(n)/factorial(n-r);
   public static void main(String args[]){
      Scanner sc = new Scanner(;
      System.out.println("Enter the value of n :");
      int n = sc.nextInt();
      System.out.println("Enter the value of r :");
      int r = sc.nextInt();
      System.out.println("npr value is ::"+npr(n,r));


Enter the value of n :
Enter the value of r :
npr value is ::24
Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician