Define Permutation & Combination in one Line with formula
Perm : When no repitetion ; n!
Comb: When repetion is allowed ;
Write a Program to find Permutation & Combination?
import java.util.Date;
import java.util.*;
public class HelloWorld {
public static void main(String[] args) { char elements[] = {'R','O','O','T'};
int noOfUniqueElements = getUniqueElements(elements); //case of PErutation
int noOfElements = elements.length; // case Of Combination
int noOFSlots = 3;
System.out.println(doPerm(noOfElements, noOFSlots));
System.out.println(doComb(noOfElements, noOFSlots));
}
private static int getUniqueElements(char elements[]){
// to do
return elements.length;
}
private static int doPerm(int noOFElements, int noOFSlots){
int perms = noOFElements;
while(noOFSlots > 1){ noOFElements = noOFElements - 1;
perms = perms * noOFElements; // mind that the perms should not bemultiplied to perms
// and also the noOfElements-1 wont work noOFSlots--;
}
return perms;
}
private static int doComb(int noOFElements, int noOFSlots){
int perms = 1;
while(noOFSlots > 0){
perms = perms * noOFElements;
noOFSlots--;
}
return perms;
}}
What strategy will you apply to find the non repeated unique number be formed inbetween 100 & 1000. Where the numbers used are 0-6 and no duplicates must come in number generations?
This is a problem of permutation
import java.util.Date;
public class HelloWorld {
public static void main(String[] args) {
int noOfElements = 5; // as the 0-6 , but the hundreath place wil be taken
int noOSlots = 3; int perms = 5; // as the very first or the hundreath place wont have 0
while(noOSlots > 1){
perms = perms * noOfElements;
noOfElements--;
noOSlots--;
}
System.out.println(perms);
}}