- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)!
Algorithm
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.
Example
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.in); 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)); } }
Output
Enter the value of n : 4 Enter the value of r : 3 npr value is ::24
- Related Articles
- C++ program to find permutation with n peaks
- Find permutation of first N natural numbers that satisfies the given condition in C++
- Program to find number of elements in all permutation which are following given conditions in Python
- Find the good permutation of first N natural numbers C++
- How to find the n number of largest values in an R vector?
- How to find the mean of every n values in an R vector?
- How to find the sum of every n values if missing values exists in the R data frame?
- Java Program To Find the Trace and Normal of a given Matrix
- Program to find last digit of the given sequence for given n in Python
- How to find the starting position for consecutive values given the length of consecutive values in an R vector?
- How to find the sum of every n values in R data frame columns?
- Program to find decode XORed permutation in Python
- C++ Program to find permutation from merged permutations
- Java program to find the sum of n natural numbers
- How to generate the permutation of x values in y positions with fixed row sums in R?

Advertisements