-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomb.java
More file actions
30 lines (27 loc) · 778 Bytes
/
comb.java
File metadata and controls
30 lines (27 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class comb {
static int factorial(int n) {
int fact = 1;
int i = 1;
while(i <= n) {
fact *= i;
i++;
}
return fact;
}
public static void main(String args[]) {
while (true){
System.out.println("This is a calculator for combination and permutation.");
int n ,r, comb, per;
System.out.println("Input the total number: ");
Scanner inp=new Scanner(System.in);
n=inp.nextInt();
System.out.println("Input the selected number you want to do: ");
r=inp.nextInt();
per = factorial(n) / factorial(n-r);
System.out.println("Permutation: " + per);
comb = factorial(n) / (factorial(r) * factorial(n-r));
System.out.println("Combination: " + comb);
}
}//main
}//class