write a program to print the factorial of first 20 even numbers using for loop java.
Answers
Answered by
5
Required Answer:-
Question:
- Write a program to print the factorial of first twenty even numbers using for loop in Java.
Solution:
Factorial of a number (N) is the product of all the numbers from 1 to N.
Here is the program.
public class FactorialEvenNum {
public static void main(String[] args) {
double p=1.0;
for(int i=1;i<=40;i++)
{
p*=i;
if (i%2==0)
System.out.println("Factorial of "+i+" is: "+p);
}
}
}
Here p calculates the factorial and it is displayed only if the number is even (as said in question, first 20 even numbers).
Output is attached.
Attachments:
Similar questions