I am trying to run a java program to find if number is palindrome or not but at the time of compilation i am getting error message as - Exception in thread "main" java.lang.Error: Unresolved compilation problem: This method must return result of type Boolean.
below is my program code :
package testing;
import java.util.Scanner;
public class PalindromeNumber {
public static void main(String[] args) {
System.out.println("Enter a number to check if it is palindrome or not :");
int number1 = new Scanner (System.in).nextInt();
if(PalindromeCheck(number1)) {
System.out.println("Number " +number1+ " is palindrome.");
}
else {
System.out.println("Number " + number1 + " is not palindrome.");
}
}
public static boolean PalindromeCheck(int number) {
int palindrome = number;
int reverse = 0;
while (palindrome !=0) {
int remainder = palindrome % 10;
reverse = reverse * 10 + remainder;
palindrome = palindrome / 10;
if (number == reverse) {
return true;
}
return false;
}
}
}