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
Blizzard [7]
3 years ago
10

Write a method called fact that recursively calculates the factorial value of its single int parameter. The value returned by fa

ct is a long ..
Computers and Technology
1 answer:
andrey2020 [161]3 years ago
6 0

Answer:

The program to this question can be given as follows:

Program:

//class

public class factorial //defining class

{

//method fact

public static long fact(int x1) //defining method fact

{

//conditional statement

if (x1 <= 1) //if block checks parameter value less then equal to 1

{

return 1; //return value

}

else //else part

{

return (fact(x1 - 1) * (long) x1); //return factors using recursive function

}

}

//method main

public static void main(String[] args) //defining main method

{

long data=fact(5);//defining variable that holds function value

System.out.println("Factorial is: "+data); //print value

}

}

Output:

Factorial is: 120

Explanation:

In the above java program, a class is "factorial" is defined, inside the class, a static method "fact" is declared, that accepts an integer parameter that is "x1" and returns a long value, inside this method a conditional statement is used.

  • If the block it checks parameter value is less then equal to 1, if this condition is true, it will return 1 when this condition is not true. It will go in else part.
  • In else part, it uses a recursive function to calculate factorial of a number and return its value.
  • Then the main method is defined, inside this method a long variable "data" is defined, that call and holds fact function return value, and in the next line, the print function is used to print the data variable value.

You might be interested in
Which type of network allows backups and network security to be centrally located?
BlackZzzverrR [31]

Answer:

B

Explanation:

B is the answer.

3 0
2 years ago
How to reduce hard drive failure data loss?
malfutka [58]
<span>Regularly schedule "fire drills" to restore information from backup
Keep it away from Dusty areas
Have a battery back up system
P</span><span>rotect equipment from static electricity that can erase data or damage components.
Hope that answers your question

</span>
7 0
3 years ago
Computer keyboard failures can be attributed to electrical defects or mechanical defects. a repair facility currently has 25 fai
Mariulka [41]
You are going to select 5 keyboards, from a set of 25 defective keyboards. When you select the first keyboard it may be have either electrical deffects or mechanical deffect, this is two possibilities. The same happens with the second, third, fourth and fifth selection. Then  each selection has 2 different possibilities, and the number of possibilities are: 2*2*2*2*2 = 32.

But that is considering that the order matters. This is that it is different that the first has electrical deffects and the others have mechanical defects than the second has mechanical electrical deffects and the other has mechanical deffects.

If you the order is not relevant, then the only different outcomes are:

1) 5 with electrical deffects
2) 4 with electrical deffects and 1 with mechanical deffects
3) 3 with electrical deffects and 2 with mechanical deffects
4) 2 with electrical deffects and 3 with mechanical deffects
5) 1 with electrical deffects and 4 with mechanical deffects
5) 5 with mechanical deffects.

In this case the answer is 6 different ways.

Answer: 6 
5 0
3 years ago
What symbol indicates that material has been copyrighted?
polet [3.4K]

Answer:

Ermmmmmm...

I Think if a thing doesn't hhave a trademark or something like that.

Explanation:

Up there

3 0
3 years ago
Read 2 more answers
Can someone please give me example of three types of loop in pascal (It has to has randomize in it too)
Lubov Fominskaja [6]

Sr.No Loop Type & Description
2 for-do loop Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
3 repeat-until loop Like a while statement, except that it tests the condition at the end of the loop body. (HOPE THIS HELPS!!)
3 0
3 years ago
Other questions:
  • Which type of energy conversion is an electric generator designed to perform?
    8·1 answer
  • 11. In Microsoft Word, when you highlight existing text you want to replace, you're in
    8·1 answer
  • What is the first step that you should undertake when performing a visual analysis of a work of art?
    6·2 answers
  • Write a static method named listcountriesoforigin, to be added to the bowl class, which is passed an array of bowl objects, and
    13·1 answer
  • If you have two pennies, the probability of both coming up heads when flipped
    13·2 answers
  • Determine the exact output of the code $str = "The quick brown fox jumps over the the lazy dog"; echo strpos($str, 'fox');
    6·1 answer
  • How do you freeze the total cell so that it doesn't change when copied?
    6·1 answer
  • Al these are benefits of computer literacy except
    14·1 answer
  • Evaluate how suitable the hardware would be for:
    12·1 answer
  • Identifiy the impact of new technology for your organizations <br>​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!