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]
2 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]2 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
Proper __ management is essenciales for meeting project deadlines​
trapecia [35]

Proper  Project management is essential for meeting project deadlines.

4 0
3 years ago
I really want to know the best way to deal as much heart as possible plz tell me
Natasha2012 [34]

Answer:

Set aside time every day for doing something that feels positive, whether that’s journaling, meeting up with a close friend, or watching a show that makes you laugh. Scheduling in moments that bring you joy is vital for healing a broken heart. It’s important to talk about your feelings with others and not numb yourself out.

Explanation:

7 0
2 years ago
Read 2 more answers
What is the difference between HTML and CSS? * 1. CSS is a markup language unlike HTML. 2. HTML is a backend technology and CSS
GarryVolchara [31]
The anserw is the third one. 
5 0
3 years ago
Read 2 more answers
[C++ for array week|
melamori03 [73]

Answer:

this is stupi

Explanation:

8 0
2 years ago
How do you think advances in processors affect corporations that discover the computers they purchased just a couple of years ag
lozanna [386]

Answer:

Increased processor speed and multi core technologies.

Explanation:

The development of processors over the years is overwhelmingly fast. The CPU use to be cumbersome, expensive and computational speed was moderate.

As it evolves, the CPU was minimized to give rise to microprocessors.

Microprocessors are very fast, running millions of processes on its core. The multiple core processors helped to increase the speed of these processors.

When there are more than one core in a processor (dual, quad or octal core), it processes data in parallel reducing the time of execution compared to a one core processor.

A company having computers with single core would need to upgrade to a new computer with multi core processor to promote speed in data processing.

3 0
2 years ago
Other questions:
  • Web storage stores data in the browser in
    5·1 answer
  • If all of Earth's history were squeezed into one 12-hour period, how long ago did Precambrian time end? How long did the Cenozoi
    15·1 answer
  • To select all the text in a document, press ____.
    12·2 answers
  • A Narrative Statement illustrates how your life will look when you reach a goal.
    15·2 answers
  • Presentation graphics programs contain an assortment of tools and operations for creating and editing slides, including preforma
    8·2 answers
  • Suppose Client A initiates a Telnet session with Server S. At about the same time, Client B also initiates a Telnet session with
    13·1 answer
  • Need the answer ASAP!!!
    5·1 answer
  • 8.
    9·1 answer
  • MP3 BrainPoP Quiz
    13·2 answers
  • With
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!