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
soldier1979 [14.2K]
3 years ago
6

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or e

qual to n. For example, 5!=5 *4* 3* 2* 1 =120 Write a programn (in Java) to print and calculate the factorial for a given (n) number
Computers and Technology
1 answer:
Daniel [21]3 years ago
3 0
I'll show a few implementations, starting with the easiest to understand.

1.) While loop.

public static void main(String[] args) {
System.out.print(factorial(n));
}

public static int factorial(String n) {
int result = 1;
while(n > 0) {
result *= n;
n--;
}
return result;
}


2.) For loop (I'll just show the contents of the factorial(String) method):

int result = 1;
for (int i = n; i > 0; i--) {
result *= i;
}
return result;


3.) Recursively.

public static int factorial(int n) {
if(n == 1) return n;
return n * factorial(n-1);
}
You might be interested in
Every windows service has the 3 start types what are those service types?
spayn [35]

Answer:

You can stop, pause, start, delay start, or resume each service as appropriate. You can also modify the start mechanism (Manual or Automatic) or specify an account. Windows Services broadly fall into three categories depending on the actions and applications they control: Local Services, Network Services and System.

5 0
3 years ago
3. What is a web directory? What are the key differences between web directories
MrMuchimi

Answer:

web directories are much smaller and more specific than search engines

3 0
2 years ago
Differentiate the threat to a computer from electrical surges and spikes versus the threat from viruses
musickatia [10]
Electrical surges can overload a computer (or really any plugged in device) and the instant jump in power can fry the computer, ruining the hardware.  viruses are made to invade youre computer through software and some viruses have the goal of finding personal information or trying to get money.  this can be done by a virus locking down your computer until you send $_____ to an account or buy something.
8 0
4 years ago
Read 2 more answers
BUURTAIS
Alisiya [41]

Answer:

what I'm confused ???????

Explanation:

?

4 0
3 years ago
. the fact that a web app is written to be run within any of the standard
Evgen [1.6K]

The correct answer is C) ease of use.

The fact that a web app is written to be run within any of the standard browser and on any platform on which that browser operates is called "ease of use."

The ease of use concept indicates that the product is "amicable" or "friendly" to use by most people because it is not required andy technical knowledge to operate the product. In this case,  the app is written to be run within any of the standard browser and on any platform on which that browser operates, so it is "friendly" to operate bu most systems. App's companies and software companies created this "ease of use" concept for many of their products so they can sell most of them because people know they are easy to use and functional.

7 0
4 years ago
Other questions:
  • What is the value of the variable result after these lines of code are executed?
    5·1 answer
  • SATCOM in the Ku- and Ka- bands, as well as EHF systems are adversely affected by rain (the higher the frequency, the greater th
    14·1 answer
  • How do you program a computer
    7·1 answer
  • What is hardware?
    10·1 answer
  • How do productivity programs most benefit the way we work and live?
    12·2 answers
  • True / False You should always consider your business requirements before deciding which designs are best for your environment.
    13·1 answer
  • ___ allow users to select controls by keyboard shortcuts. (Points : 3) Alternative keys
    13·1 answer
  • A restaurant recorded the ages of customers on two separate days. You are going to write a program to find the minimum age of a
    5·2 answers
  • Select the correct answer
    15·1 answer
  • How are the four characteristics of the db approach related to the four functions of a dbms?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!