What Im trying to code is that a user inputs a number n and the program outputs all the numbers from 1 to n that are both prime numbers and palindrome numbers. I created a method for finding prime numbers and another for finding if a number is a palindrome. My code for outputting the integers that are both goes like
if ((prime(y)==true) && (pal(y)==n)) {
System.out.println(y);
}
Here is my method for finding prime numbers:
public static boolean prime(int n) {
int x = 2;
while (n%x>0) {
x+=1;
} if (x==n) {
return true;
} else {
return false;
}
}
Here's my method for finding palindrome numbers:
public static boolean pal(int n) {
int rev = 0;
int rmd = 0;
while (n>0) {
rmd = n%10;
rev = rev*10 + rmd;
n = n/10;
} if (rev==n) {
return true;
} else {
return false;
}
}
I get the error that these two methods are not comparable because apparently one is boolean and the other integer. Anyone know how to fix this?