Write a Java program to find the factorial of a number by taking input from user
Answers
Answer:
Factorial of a number in Java
import java
class Factorial
{
public static void main(String args[])
{
int n, c, f = 1;
System.out.println("Enter an integer to calculate its factorial");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if (n < 0)
System.out.println("Number should be non-negative.");
else
{
for (c = 1; c <= n; c++)
f = f*c;
System.out.println("Factorial of "+n+" is = "+f);
}
}
}
Explanation:
Hope it helps uh...
Hope it helps uh...Plz mark as a brainliest answer...
Answer:
Explanation:
class Factorial
{
public static void main(Strign arr[])
{
Scanner sc=new Scanner(System.in);
int i,f=1,n;
System.out.println("Enter a number:");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
f=f*i;
}
System.out.println("Factorial="+f);
}
}