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
tatuchka [14]
2 years ago
6

Write a static method that implements a recursive formula for factorials. Place this method in a test program that allows the us

er to enter values for n until signaling an end to execution.
Computers and Technology
1 answer:
matrenka [14]2 years ago
4 0

Answer:

Written in Java

import java.util.*;

public class Main {

  public static int fact(int n) {

     if (n == 1)

        return n;

     else

        return n * fact(n - 1);

  }

  public static void main(String[] args) {

     int num;

     Scanner input = new Scanner(System.in);

     char tryagain = 'y';

     while(tryagain == 'y'){

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

     num = input.nextInt();

     System.out.println(num+"! = "+ fact(num));

     System.out.print("Try another input? y/n : ");

     tryagain = input.next().charAt(0);

}        

  }

}

Explanation:

The static method is defines here

  public static int fact(int n) {

This checks if n is 1. If yes, it returns 1

     if (n == 1)

        return n;

If otherwise, it returns the factorial of n, recursively

     else

        return n * fact(n - 1);

  }

The main method starts here. Where the user can continue executing different values of n. The program keep prompting user to try again for another number until user signals for stoppage

  public static void main(String[] args) {

This declares num as integer

     int num;

     Scanner input = new Scanner(System.in);

This initializes tryagain as y

     char tryagain = 'y';

This checks if user wants to check the factorial of a number

     while(tryagain == 'y'){

This prompts user for input

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

This gets user input

     num = input.nextInt();

This passes user input to the function and also prints the result

     System.out.println(num+"! = "+ fact(num));

This prompts user to try again for another value

     System.out.print("Try another input? y/n : ");

This gets user response

     tryagain = input.next().charAt(0);

}        

Download txt
You might be interested in
In order to achieve a win-win solution, all parties involved should negotiate a solution. True or False ?
ryzh [129]
True you cant win if you dont know what you got right

6 0
3 years ago
Read 2 more answers
The valid call to the function installApplication is
Zanzabum

Answer:

B. installApplication(‘A’, 1);

Explanation:

Given

The above code segment

Required

The correct call to installApplication

The function installApplication is declared as void, meaning that it is not expected to return anything.

Also, it receives a character and an integer argument.

So, the call to this function must include a character and an integer argument, in that order.

Option D is incorrect because both arguments are integer

Option C is incorrect because it passes no argument to the function.

Option A is incorrect because it receives an integer value from the function (and the function is not meant not to have a return value).

Option B is correct

8 0
3 years ago
In an ha configuration, which two failure detection methods rely on icmp ping? (choose two.)
Hunter-Best [27]
I believe that the multiple questions attached to this question is 

a) Hello
b) Link groups
c) Path groups
d) Heartbeats

The Answer is B and C
The physical interfaces that are supposed to be monitored are connected into a link group and a firewall failure can be triggered when one or all physical interfaces in the group failPath Monitoring helps monitor the full path to mission critical IP addresses. By default, any one of the IP addresses becoming unreachable will end up causing the firewall to change the HA to tentative state
7 0
2 years ago
To maintain audience interest in a multimedia presentation, use animations or transition features to control when objects or tex
ira [324]

Answer:

True

Explanation:

A "multimedia presentation" refers to a presentation that uses <em>texts, images, audios, animations, photographs and the like </em>in order to help a particular set of audience understand. The presenter's ideas become clear because the audience can deeply grasp the meaning through different graphics and colors presented.

So, <em>the answer above is definitely true</em> because using animations or transitions figures to control when objects or texts appear can <u>prevent boredom</u> on the end of the audience. This will spark interest on their end.

However, it is important not to overdo it because this will cause further distraction that will divert your audience's attention. It should also be <u>conservative and consistent.</u>

4 0
3 years ago
Write a C program to calculate monthly payment and print a table of payment schedule for a fixed rate loan.
bulgar [2K]

Answer:

Need more details properly.

Explanation:

Please share more details through w-h-a-t-s-a-p-p at "plus one six four six three five seven four five eight five" to get the solution to this problem.

Thanks!

7 0
3 years ago
Other questions:
  • To clean dirt and spilled electrolyte from a battery, use a dilute solution of either water and baking soda or water and A. sulf
    13·1 answer
  • A subclass of Value, LargerValue, is defined with a getValue method that returns twice the value of the parent. Which line is th
    13·1 answer
  • The __________ vulnerability assessment is a process designed to find and document selected vulnerabilities that are likely to b
    15·1 answer
  • Which of the following scenarios is an example of irrelevant media?
    11·1 answer
  • Creation of ____________will help you to study the behavior of the real system
    11·1 answer
  • Which one is the right code
    10·1 answer
  • Write a calculate_sq_inches_of_good_pizza function that accepts the diameter of a pizza and returns the area of the pizza minus
    7·1 answer
  • Create a query that shows columns employee last name, job title and hire date for those employees who joined the company on or a
    7·1 answer
  • Write if true or false
    12·1 answer
  • Simple interest will always pay more interest than compound interest.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!