In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
import java.util.*;
public class Javaexcercise {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a integer: ");
int num = in.nextInt();
System.out.printf("Is %d is a palindrome number?\n",num);
System.out.println(palindrome(num));
}
private static boolean palindrome(int num) {
String str = String.valueOf(num);
int i = 0;
int j = str.length() - 1;
while (i < j) {
if (str.charAt(i++) != str.charAt(j--)) {
return false;
}
}
return true;
}
}
In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..
Result:
Enter a integer: 1221
Is 1221 is a palindrome number?
true
need an explanation for this answer? contact us directly to get an explanation for this answer