answer.
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
koban
21 day ago
9

Debug the program so it prints the factorial of a positive integer entered by the user. This is calculated by multiplying all th

e numbers from 1 up to that number together. For example, 5 factorial is 5*4*3*2*1 = 120.
import java.util.Scanner;

public class U4_L1_5_Activity_Two{
public static void main(String[] args){

Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
while(num >= 0){
int prod = 1;

prod = prod*num;
System.out.print(prod);
num--;
}


}
}
Computers and Technology
1 answer:
Natasha_Volkova [897]21 day ago
3 0
The primary issue was declaring int prod within the while loop, which caused prod to reset to 1 each time the loop executed.
You might be interested in
A network administrator notices that some newly installed Ethernet cabling is carrying corrupt and distorted data signals. The n
zubka84 [945]

Answer:

EMI and RFI

Explanation:

EMI, or Electromagnetic Interference, can also be referred to as Radio-frequency Interference (RFI) within the radio frequency domain.

An unshielded ethernet cable, made from copper, might function as an antenna; any external noise that interferes with it can corrupt the data signal, resulting in data integrity issues and distorted signals.

6 0
8 days ago
In mathematics, the factorial of a positive integer n, denoted as n! , is the product of all positive integers less than or equa
oksian1 [804]
public static int factorial(int n) { if (n >= 1 && n <=12) { if (n == 1) return 1; else return n * factorial(n - 1); } else return -1; } Explanation: The factorial method takes a single integer n as input. It checks if n is within the range of 1 to 12. If it is, it further checks if n equals 1. If it is indeed 1, it returns 1 as the factorial. Otherwise, it recursively calls itself with n decreased by 1, multiplying the result by n. If n is outside this range, the method returns -1 indicating the input is invalid.
6 0
11 days ago
Read 2 more answers
Assume that you are testing the Orders database introduced in Watt (2014) - Appendix C. Discuss the problems and possible conseq
ivann1987 [930]

Answer:

129 \frac{2}{?} 23.4. \div 164 \times 5y1 +. \\.00487ggh

6 0
18 days ago
Currently, this program will add 6 and 3 together, output the math problem and output the answer. Edit this code so that a rando
8_murik_8 [892]

I have attached my code in the image below. Good luck.

6 0
1 month ago
c++ You are given an array A representing heights of students. All the students are asked to stand in rows. The students arrive
maria [879]

The following code will assist you in solving the specified problem; you can run it and verify against some sample input and output.

#include<stdio.h>

#include<string.h>

 int* uniqueValue(int input1,int input2[])

 {

   int left, current;

   static int arr[4] = {0};

   int i      = 0;

     for(i=0;i<input1;i++)

      {

         current = input2[i];

         left    = 0;

         if(current > 0)

         left    = arr[(current-1)];

      if(left == 0 && arr[current] == 0)

       {

       arr[current] = input1-current;

       }

       else

   {

       for(int j=(i+1);j<input1;j++)

       {

           if(arr[j] == 0)

           {

               left = arr[(j-1)];

               arr[j] = left - 1;

           }

       }

   }

}

return arr;

}

4 0
11 days ago
Other questions:
  • How concerned are you about the security of rtos in cars smart homes and wearable technology?
    15·1 answer
  • Charlie has a large book collection. He was keeping track of it in a spreadsheet, but it has grown big enough that he wants to c
    10·1 answer
  • for question 1-3, consider the following code what is output if the user types in 9? click all that apply A, B, C, D click all t
    13·1 answer
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • To finish creating a design for the webpage, use one shape to cut away part of the other. Create a 700 pixel by 700 pixel square
    10·1 answer
  • Write measurable performance objectives.Suppose that a trainer has identified as a generalgoal for a training module,"Able to fo
    13·1 answer
  • 6. A small design agency you are consulting for will be creating client websites and wants to purchase a web server so they can
    6·1 answer
  • Describe a situation involving making a copy of a computer program or an entertainment file of some sort for which you think it
    7·1 answer
  • What advantage do ExpressCard modules and USB adapters offer over expansion cards?
    5·1 answer
  • What feature would be used to collect how many times users downloaded a product catalog?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!