in Java Create a Statistics class that provides three methods: Factorial permuta
ID: 3886204 • Letter: I
Question
in Java
Explanation / Answer
Output:
Code:
public class Statistics{
static int factorial(int n){
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
public static int permutation(int n,int k ){
int n1 = factorial(n);
int n2 = factorial(n-k);
int r = n1/n2;
return r;
}
public static int combination(int n , int k ){
int n1 = permutation(n,k);
int n2 = factorial(k);
int r = n1/n2;
return r;
}
public static void main(String args[]){
int i,fact=1;
int number=5;
int k = 3;
int n = 7;
int k2 = 2;
int n2 = 8;
fact = factorial(number);
int p = permutation(n,k);
int c = combination(n2,k2);
System.out.println("factorial of " + number + "is: " + fact );
System.out.println("Permutation of "+n+","+k+" is: "+p);
System.out.println("Combination of "+n2+","+k2+" is: "+c);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.