66. JAVA Program to find all the Factorial Prime numbers from 1 to 99.
How does this program work?
- This program is used to find all the factorial prime numbers from 1 to 99 using java.
- Prime number means which is only divisible by 1 and that number itself, and cannot divisible by any other number.
- First store the number into variable, then we will find the remainder using loop.
- The counter will be increment if remainder zero, Once number can be divisible by some other number instead of 1 and that number itself, If its value less than three means its a primer number.
Here is the code
//To find all the factorial prime numbers from 1 to 99
public class Prime{
public static void main(String args[])
{
long i,j,k,count,first,last,sum=0,fact=1;
for ( i= 2; i<= 5; ++i )
{
count=0;
for ( k=2; k<=i/2; k++ )
{
if (( i % k ) == 0 )
{
count++;
}
}
if ( count==0 )
{
fact=1;
for ( j=1;j<=i;j++ )
{
fact*=j;
}
sum+=fact;
}
}
System.out.println("\n Sum of prime numbers factorial is: "+sum);
}
}