Java Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 9: Write a Java program to calculate the permutation of a given number.

import java.util.Scanner;

public class Permutation
	// fact()- A method to calculate factorial.
	static int fact(int num)
		int factorial=1;
		for(int i=2;i<=num;i++)
		return factorial;
 	//main method
	public static void main(String[] args) 
		Scanner s =new Scanner(;
		int n,r;
		System.out.println("Enter the value of n");
		System.out.println("Enter the value of r");

		//calculating nPr = (n)!/(n-r)!
		//calling the method fact() to calculate the factorial.
		double permutation= fact(n)/fact(n-r);

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.