wap in java to find prime factorials of a number given by user
Answers
Answered by
2
Question:-
Write a program in java to find prime factorials of a number.
Program:-
import java.util.*;
class Primorial
{
public static void main(String args[])
{
long f=1L;
int n, i;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
n=sc.nextInt();
for(i=2;i<=n;i++)
{
if(isPrime(i))
f*=i;
}
System.out.println("Primorial of the number is: "+f);
}
static boolean isPrime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
return (c==2);
}
}
Similar questions