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
Aleks [24]
3 years ago
6

2. The factorial of a positive integer n is the product of the integers from 1 to n. You can express the factorial of a positive

integer n (in mathematics this is denoted by n!) using the following formula: n! = 1 * 2 * 3 * ... * (n - 1) * n Write a Java program that will compute the factorial of some numbers n (input from the user, accept only range 1 - 10). For each valid number in input, the output should be the value of n!. Your program should use a loop, to allow the user to input more than one number (count-controlled or sentinel-controlled, your choice)
Computers and Technology
1 answer:
Molodets [167]3 years ago
6 0

Answer:

import java.io.*;

import java.util.Scanner;//importing the scanner.

class Factorial {

public static void main (String[] args) {

    Scanner fact=new Scanner(System.in);//creating a scanner object for taking the input.

    int t,n;//t for number of times the user want to calculate the factorial and n for factorial.

    System.out.println("How many times you want to calculate the factorial");

    t=fact.nextInt();//taking input of t.

    while(t>0)

    {

        int f=1;//f for calculating the variable.

        n=fact.nextInt();//taking input of n .

        if(n>10||n<1)//if n is out of range then again taking input.

        {

           while(n>10 || n<1)

                {

                        System.out.println("Please Enter the Valid Input");

                 n=fact.nextInt();

                }

               for(int i=1;i<=n;i++)//calculating the factorial.

               {

                   f*=i;

               }

               System.out.println("The factorial is: "+ f);

        }

        else // if n is in  range then definitely calculating the factorial.

        {

             for(int i=1;i<=n;i++)// calculating the factorial.

               {

                   f*=i;

               }

               System.out.println("The factorial is: "+ f);

        }

    }

}

}

Output:-

How many times you want to calculate the factorial

2

-5

Please Enter the Valid Input

4

The factorial is: 24

5

The factorial is: 120

Explanation:

The above written code is for calculating the factorial of an integer the number of times user want to calculate the factorial.The code wants user to enter again until the value entered by the user is in range.If the value is in range then it definitely calculates the factorial.

You might be interested in
Write the steps for displaying multiple subtotal functions in excel.
Sloan [31]

We can display multiple subtotal functions in excel using the following steps.

<u>Explanation</u>:

Step1: Enter the data you want to add in the excel sheet.

Step2: Select the cell containing the data you want to add.

Step3: Click the Data Tab

Step 4: Now select the SUBTOTAL command in the outline group.

Step 5: An option called ATEACHCHANGEIN will be available.

Step 6: Now select the drop-down menu under that option.

Step 7: After selecting the drop-down menu to select the columns you want to use for the first level subtotals.

By following these steps, we can display multiple subtotal functions in excel.

3 0
3 years ago
What is the 5 basic steps of computer programing?
arsen [322]
1. Learning Languages such as C+, VB, etc.
2. Gather data, proficient websites that will come to your need.
3. Install certain softwares to see it in action.
4. Do lots and lots of studying and research.
5. Ask for help, the Internet is here.
7 0
3 years ago
How can presentation software be used in a
atroni [7]

Answer:

to compose letters and memos

to create charts and graphs from a table of

values

to deliver a sales presentation to clients

Explanation:

I forget what the reasoning behind them but I know this is the answer

7 0
3 years ago
Read 2 more answers
List and describe three options in the autocad object snap toolbar
miv72 [106K]
<span>END POINT : Snaps to the closest endpoint or corner of a geometric object. MID POINT : Snaps to the midpoint of a geometric object. CENTER : Snaps to the center of an arc, circle, ellipse, or elliptical arc.</span>
6 0
3 years ago
What kind of attack allows for the construction of LDAP statements based on user input statements, which can then be used to acc
abruzzese [7]

Answer:   b. LDAP injection

Explanation:

LDAP (Lightweight Directory Access Protocol ) Injection is defined as

  • an injection attack used by attacker to exploit web based applications by inserting LDAP statements based on user input.
  • It may be possible modify LDAP statements through some techniques if an application fails to properly sanitize user input.

So,<u> LDAP injection</u> is the attack that allows for the construction of LDAP statements based on user input statements, which can then be used to access the LDAP database or modify the database's information.

Hence, the correct option is b. LDAP injection.

4 0
3 years ago
Other questions:
  • Use cases can be used to document both the current (As-Is) system and the future (To-Be) system. A. True B. False
    13·1 answer
  • 6.67
    5·1 answer
  • In addition to training on the products and on company policy, it does not make sense to be prepared to speak about your company
    6·2 answers
  • The mutt software is an example of what type of mail service software on Linux? a. Mail Delivery Agent b. Mail Transport Agent c
    5·1 answer
  • Nikolas has a idea that he could use the compressed carbon dioxide in a fire extinguisher to propel him on his skateboard. Nikol
    13·2 answers
  • In excel, which symbol means not equal to when comparing two values?
    15·1 answer
  • Availability is an essential part of ________ security, and user behavior analysis and application analysis provide the data nee
    14·1 answer
  • Write the correct statements for the above logic and syntax errors in program below.
    12·1 answer
  • Write code which takes two inputs from the user, a number of sides followed by a side length, then creates a regular polygon wit
    10·2 answers
  • Frank enters "1" in the field for postal code. What is frank most likely trying to do?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!