I need help with my Java Programming homework here\'s the info: Create a program
ID: 3733288 • Letter: I
Question
I need help with my Java Programming homework here's the info:
Create a program using a web solution that allows you to enter an integer between 1 and 10 and returns a factorial of the integer you typed in. The factorial calculation should be placed in its own method within your program.
Factorial:
In mathematics, the factorial of a positiveinteger n,[1] denoted by n!, is the product of all positive integers less than or equal to n. For example,
5! = 5*4*3*2*1 or 120
This program should be solved using a web page.
Explanation / Answer
FactorialDemo.java
import java.util.Scanner;
public class FactorialDemo {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter in N: ");
int n = scan.nextInt();
System.out.println("Factorial = "+factorial(n));
}
public static int factorial(int n) {
int product = 1;
for(int i=1; i<=n ;i++){
product = product * i;
}
return product;
}
}
Output:
Enter in N: 5
Factorial = 120
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.