Question

In: Computer Science

Replace <missing value> and <missing code> with your answers. Your code should compute the factorial of...

Replace <missing value> and <missing code> with your answers. Your code should compute the factorial of n. For example, if n = 5, your code should compute the following 5 * 4 * 3 * 2 * 1 (which is 120).

public static void main(String[] args)
{

Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();

int factorial = <missing value>;

<missing code>

System.out.println("factorial = " + factorial);

Solutions

Expert Solution

If you have any doubts, please give me comment...

import java.util.Scanner;

public class Factorial {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int factorial = 1;

        for (int i = n; i > 0; i--) {

            factorial *= i;

        }

        System.out.println("factorial = " + factorial);

    }

}


Related Solutions

There is a Java program that is missing one recursive function: public class Factorial { /*...
There is a Java program that is missing one recursive function: public class Factorial { /* / 1 when n is 0; * fact(n) = | * \ n*fact(n-1) otherwise */ public static int fact(int n) { return 0; } /* Factorial Test Framework * * Notice the odd expected value for fact(20). It is negative because * fact(20) should be 2432902008176640000, but the maximum int is only * 2147483647. What does Java do when integers run out of range?...
Complete this question by entering your answers in the tabs below. Fill in the missing amounts...
Complete this question by entering your answers in the tabs below. Fill in the missing amounts in the following schedules. April May June Sales* $276,000 $207,000 Cash receipts: From cash sales $156,600 From sales on account† 117,300 Total cash receipts ​ Accounts payable, 12/31/x0 €654,000 Purchase of goods and services on account during 20x1 276,000 Payments of accounts payable during 20x1 Accounts payable, 12/31/x1 €872,000 Accounts receivable, 12/31/x0 ¥1,880,000 ‡ Sales on account during 20x1 4,716,000 Collections of accounts receivable...
(a) Fill in the missing blanks on the following ANOVA table. (Enter your answers as whole...
(a) Fill in the missing blanks on the following ANOVA table. (Enter your answers as whole numbers except for the test statistic value. Round the test statistic value to three decimal places.) ANOVA Source DF SS MS F-Statistic Regression 2 8 Error (Residual) 180 Total 92 (b) How many explanatory variables were in this model? (Enter your answer as a whole number.) (c) What was the sample size of the data set this model was built upon? (Enter your answer...
Present Value Computations Assuming that money is worth 10%, compute the present value of Round answers...
Present Value Computations Assuming that money is worth 10%, compute the present value of Round answers to the nearest whole number. 1. $7,000 received 15 years from today. $Answer 2. The right to inherit $1,000,000 14 years from now. $Answer 3. The right to receive $1,000 at the end of each of the next six years. $Answer 4. The obligation to pay $3,000 at the end of each of the next 10 years. $Answer 5. The right to receive $5,000...
compute and print factorial if it is equal to 6, not equal to 6, and square...
compute and print factorial if it is equal to 6, not equal to 6, and square of the factorial, if the input is equal to 6 ..... C programming
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
Compute the additional Medicare tax for the following taxpayers. If required, round your answers to the...
Compute the additional Medicare tax for the following taxpayers. If required, round your answers to the nearest dollar. a. Mario, who is single, earns wages of $589,200 in 2018. His total Medicare tax is $________. b. George and Shirley are married and file a joint return in 2018. During the year, George earns wages of $205,100, and Shirley earns wages of $307,650. Their total Medicare tax is $______. c. Simon has net investment income of $45,680 and MAGI of $228,400...
What is my code missing? // chStr.cpp // Put your name here // Pseudocode #include #include...
What is my code missing? // chStr.cpp // Put your name here // Pseudocode #include #include <___> #include using namespace std; const string ANAME = "Katia Kool"; const char AGRADE = 'A'; const double COMMISSION_RATE_A = 0.02625; const ___; . . . // likewise, constants for Betty int main() {        int numberOfShares = 622;                // number of shares        double pricePerShareA = 21.77;           // price per share        double pricePerShareB = 12.44;           // price per share        double stockA,...
1. Please give concise and precise answers for the following questions. Your answers should be no...
1. Please give concise and precise answers for the following questions. Your answers should be no more than five (5) sentences. a) What is consolidation (5 points)? b) Is consolidation the only reason why soil layers having settlements (5 points)? c) Under what kind(s) of condition will soil layers consolidate (5 points)? d) What are the basic assumptions of Terzaghi’s consolidation theory (5 points)? e) Based on the consolidation theory proposed by Karl Terzaghi, which factor from the results of...
A column in your data is missing a value in one row. Which command fills this...
A column in your data is missing a value in one row. Which command fills this missing data point with the value before it? Select an answer: df.fillna(method='bfill') df.fillna(0) df.fillna(method='linear') df.fillna(method='ffill')
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT