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.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?
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
Animation timing is does not affect the
speed of the presentation
Select one:
True
False
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
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); }
}