Given three numbers as input, return true if at least one of them is a prime number. For solving this problem, define a function that checks whether a number is a prime or not and use that function
MyApproach:
I made a function that checks first whether the num is prime or not(CHECK PRIME).After checking the 3 numbers,if in that function any of the number is prime it should return true otherwise false.
But I am getting wrong Ans for the test case
Below is my Code:
public boolean anyonePrime(int num1, int num2, int num3)
{
boolean b1=checkPrime(num1);
boolean b2=checkPrime(num2);
boolean b3=checkPrime(num3);
if((b1==true) ||(b2==true) ||(b3=true))
return true;
else
return false;
}
public boolean checkPrime(int num)
{
boolean b0=true;
if(num==1)
b0=false;
else
{
for(int i=2; i<=num/2; i++)
{
if(num % i == 0)
{
b0=false;
}
}
}
b0=true;
if(b0==true)
return true;
else
return false;
//write your code here
}
}
For the Input
Parameters ActualOutput Expected Output
'169' '361' '529' true false
Aucun commentaire:
Enregistrer un commentaire