1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jekas [21]
3 years ago
9

Write a recursive method called permut that accepts two integers n and r as parameters and returns the number of unique permutat

ions 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.
Computers and Technology
1 answer:
tangare [24]3 years ago
8 0

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.
You might be interested in
Which of the following is NOT a possible combination of values of the variables in this program when it finishes running?
Nady [450]

Answer:

Definitely D

Explanation:

When you flip a coin it’s a 50/50 chance. Meaning it’s equal.

7 0
3 years ago
Read 2 more answers
What does the process of email encryption involve??
stealth61 [152]

Answer: Option C

Explanation:

4 0
3 years ago
The _____ command icon looks like a small clipboard with a page attached.
NISA [10]
The COPY command icon looks like a clipboard with a page attached.
3 0
3 years ago
Write a full class definition for a class named Averager, and containing the following members:______An data member named sum of
alina1380 [7]

Answer:

  1. public class Averager {
  2.    private int sum;
  3.    private int count;
  4.    public Averager(int sum, int count) {
  5.        this.sum = 0;
  6.        this.count = 0;
  7.    }
  8.    public int getSum(){
  9.        return sum;
  10.    }
  11.    public void add( int num){
  12.        this.sum+=num;
  13.        this.count++;
  14.    }
  15.    public int getCount(){
  16.        return this.count;
  17.    }
  18.    public double getAverage(){
  19.        double ave = (int)this.sum/this.count;
  20.        return  ave;
  21.    }
  22. }

Explanation:

  • Lines 1-3 contains the class declaration and the member (data fields)
  • Lines 4-7 is the constructor that initializes the fields to 0
  • Lines 8-10 is the method that returns the value of sum getSum()
  • lines 11-14 iss the method add() that adds a number to the member field sum and increases count by 1
  • lines 15 - 17 is the method that returns total count getCount()
  • Lines 18-21 is the method getAverage() That computes the average and returns a double representing the average values

6 0
4 years ago
Read 2 more answers
If you wanted to make the system sequentially consistent, what are the key constrains you need to impose
HACTEHA [7]

Answer:

The call of instructions and data must be sequential, there can be no reordering of instructions but to allow reordering, a fence must be created.

Explanation:

Sequential consistent memory model is able to use instructions when or before processing is done and after processing, so long as the instruction order is sequential.

This is similar to uploading a video on you-tube, the site immediately creates a page for the video even before the video is fully uploaded. Sent tweeter messages are seen by different people at different times, but the messages appear to be arranged sequentially.

6 0
4 years ago
Other questions:
  • You will be administratively suspended if you have a breath or blood alcohol level of.... or above or refuse to submit to a chem
    12·1 answer
  • If a CPU receives theinstruction to multiply the byte-sized values $12 and $3E, thisaction will take place in the ______________
    13·1 answer
  • When users talk about font size,
    10·2 answers
  • What is the name of the formal procedure scientists use to study the world around them?
    14·2 answers
  • Spell checker will find every mistake you make in a document and correct it. A. True B. False
    9·2 answers
  • While in class you were introduced to the varieties
    7·1 answer
  • JAVA
    10·1 answer
  • What are the differences between switches and routers? cse question
    8·1 answer
  • Mention 5 types of assembly language​
    6·1 answer
  • Select each of the steps involved in creating a table in a presentation.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!