comparing dynamic int value to reverse of its value, not comparing properly.
import java.util.Scanner; @SuppressWarnings("all") public class Palindrome { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Enter any number to check if its palindrome or not :"); Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int rev = 0,temp; //temp = num; while(num != 0) { rev = rev * 10; rev = rev + num%10; num = num / 10; } System.out.println(rev); if(rev == num) { System.out.println("Its a palindrome number"); }else { System.out.println("Its not a palindrome number"); } } } when comparing 2 int values whether they are same or not, in this palindrome program, the control is going to the "ELSE" part, but if I assign the "num" value to "temp" and in IF clause if i give -> if(rev == temp), then its working properly. Why is it happening like this??