A Sphenic Number is a positive integer n which is product of exactly three distinct primes. The first few sphenic numbers are 30, 42, 66... Given a number n, determine whether it is a Sphenic Number or not.
What's wrong with my code?
mport java.util.*;
class Sphenic
{
public boolean checkPrime(int n)
{
int i,c=0;
{
for(i=0;i<=n;i++)
{
if(n%i==0)
{
c++;
}
if(c==2)
{
return true;
}
else
{
return false;
}
}
}
}
public static void main()
{
Scanner in=new Scanner (System.in);
int no,i,j,k,flag=0;
System.out.println("Enter the number");
no=in.nextInt();
boolean ans1,ans2,ans3;
Sphenic obj=new Sphenic();
for(i=2;i<=no;i++)
{
ans1=checkPrime(i);
if(ans1==true)
{
for(j=2;j<=no;j++)
{
ans2=checkPrime(j);
if(ans2==true)
{
for(k=2;k<=no;k++)
{
ans3=checkPrime(k);
if(ans3==true)
{
if(i!=j && j!=k && k!=i && i*j*k==no)
{
flag=1;
}
}
}
}
}
}
}
if(flag==1)
{
System.out.println("The number is a Sphenic number");
}
else
{
System.out.println("The number is not a Sphenic number");
}
}
}