Write a recursive method called permut that accepts two integers n and r as parameters and returns the number of unique permutations of r items from a group of n items. For given values of n and r, this value P(n, r) can be computed as follows:
n!/(n - r)!
For example , permut (7, 4) should return 840.

Answers

Answer 1

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.

Related Questions

Suppose you are choosing between the following three algorithms:
• Algorithm A solves problems by dividing them into five subproblems of half the size, recursively solving each subproblem, and then combining the solutions in linear time.
• Algorithm B solves problems of size n by recursively solving two subproblems of size n − 1 and then combining the solutions in constant time.
• Algorithm C solves problems of size n by dividing them into nine sub-problems of size n=3, recursively solving each sub-problem, and then combining the solutions in O(n2) time.
What are the running times of each of these algorithms (in big-O notation), and which would you choose?

Answers

Answer:

Algorithm C is chosen

Explanation:

For Algorithm A

T(n) = 5 * T ( n/2 ) + 0(n)

where : a = 5 , b = 2 , ∝ = 1

attached below is the remaining part of the solution

Acróstico sobre mouse

Answers

this is a PICTURE

i HOPE IT'S HELP

Animation timing is does not affect the
speed of the presentation
Select one:
True
False​

Answers

Answer:

True

Explanation:

I think it's true.....

This lab was designed to teach you more about using Scanner to chop up Strings. Lab Description : Take a group of numbers all on the same line and average the numbers. First, total up all of the numbers. Then, take the total and divide that by the number of numbers. Format the average to three decimal places Sample Data : 9 10 5 20 11 22 33 44 55 66 77 4B 52 29 10D 50 29 D 100 90 95 98 100 97 Files Needed :: Average.java AverageRunner.java Sample Output: 9 10 5 20 average = 11.000 11 22 33 44 55 66 77 average = 44.000 48 52 29 100 50 29 average - 51.333 0 average - 0.000 100 90 95 98 100 97 average - 96.667

Answers

Answer:

The program is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

 String score;

 System.out.print("Scores: ");

 score = input.nextLine();

 String[] scores_string = score.split(" ");

 double total = 0;

 for(int i = 0; i<scores_string.length;i++){

     total+= Double.parseDouble(scores_string[i]);  }

 double average = total/scores_string.length;

 System.out.format("Average: %.3f", average); }

}

Explanation:

This declares score as string

 String score;

This prompts the user for scores

 System.out.print("Scores: ");

This gets the input from the user

 score = input.nextLine();

This splits the scores into an array

 String[] scores_string = score.split(" ");

This initializes total to 0

 double total = 0;

This iterates through the scores

 for(int i = 0; i<scores_string.length;i++){

This calculates the sum by first converting each entry to double

     total+= Double.parseDouble(scores_string[i]);  }

The average is calculated here

 double average = total/scores_string.length;

This prints the average

 System.out.format("Average: %.3f", average); }

}

Other Questions
How can I solve this quadratic using the square root properly? URGENT PLZ HELPWhich of the following statements is true?a. In an endothermic process heat is transferred from the surroundings to thesystem.b. In an exothermic process heat is transferred from the surroundings to thesystem.C. The surroundings will feel cooler in an exothermic process.d. The surroundings will feel warmer in an endothermic process. A certain bacterium splits itself into 2 identical cells in 1 day. Each of those new cells is capable of splitting itself into 2 identical cells in 1 day. So the first day there are 2 cells, the second day there are 2 x 2 cells, and so on. Write and evaluate an expression using a base and an exponent to represent the number of cells present at the end of the 7th day. Find the value of x in the triangle shown below 8 10 What evidence have you discovered to explain how cells are organized in the body, similar to the way dots in pointillism art is organized. For the following right triangle, find the side length x. Round your answer to the nearest hundredth.138 PLEASE HELP ME!!!!IT IS FOR BIOLOGY!!! Substitution x+5y=13, 4x+7y=0PLEASE HELP MEE In which biome would you expect to find the greatest biodiversity? aTundra bConiferous Forest cDesert dTropical Rain Forest can u help me learn Spanish Apply the problem-solving techniques to solve the followingproblem.Population decrease In 1990, a rural area had 1200 birdspecies. If species of birds are becoming extinct at the rate of1.5% per decade (10 years), how many bird species will there beleft in theyear2020? HELP!!!!!!!!!!!!!! ASAP! guyssss ANYONEEE PLSSS!!!!!I NEED HELP LIKE ACTUALLY 9)5.6 yd5 yd12 ydFind the area. (A = 1/2 ( 61 + b2) h) An object is located 20.0 cm from a convex lens. The lens focuses light at adistance of 10.0 cm. What is the image distance?A. 6.67 cmB. -6.67 cmC. -20.0 cmD. 20.0 cm Les 2/3 de 9Litres ? What is the surface area of the cylinder with height 6 in and radius 7 in? Round your answer to the nearest thousandth. PLEASE HELP ME ILL GIVE 70 POINTS AND MARK BRAINLIEST The Vietnam war was so unpopular, Lyndon Johnson:A. Chose to withdraw all American forces from the country.B. Focused on his domestic policy instead.C. Chose not to run for reelection.D. Lost the 1968 election. PLEASE HELP 25 POINTSThe topographic map shows the location of a park ranger at Point X when a message is received that an injured hiker needs help at Point Z. Which answer correctly identifies the elevations of both points on the map?Point X= 1500m, Point Z= 2000mPoint X= 1550m, Point Z= 1600mPoint X= 1600m, Point Z= 2050mPoint X= 2050m, Point Z= 1600m