Answer:
Following are the code to the given question:
public class Main//defining a class Main
{
static int permut(int n, int r)//defining a method permut that holds two variable
{
return fact(n)/fact(n-r);//use return keyword to return calcuate value
}
static int fact(int n)//defining a fact method as recursive to calculate factorials
{
return n==0?1:n*fact(n-1);//calling the method recursively
}
public static void main(String[] abs)//main function
{
//int n=7,r=4;//defining integer variable
System.out.println(permut(7,4));//use print method to call permut method and print its values
}
}
Output:
840
Explanation:
Following is the explanation for the above code.
- Defining a class Main.
- Inside the class two methods, "permut and fact" were defined, in which the "permut" accepts two values for calculating its permutated value, and the fact is used for calculates factorial values recursively.
- At the last, the main method is declared, which uses the print method to call "permut" and prints its return values.