My Java code is here:
import java.util.Scanner;
public class task2 {
public static void main(String args[]) {
System.out.print(\"Input a 3 digit int
When you do the following operation on x
:
x /= 10;
you're modifying its value - so it no longer contains the input from:
int x = scan.nextInt();
As Narendra Jadon suggested - you can save the original value into another variable and use it when you try to compare:
if (x == isPalindrome){
Alternative solution that uses "conversion" of the int to String:
public boolean isPalindrom(int n) {
return new StringBuilder("" + n).reverse().toString().equals("" + n);
}