Palindrome number in java from 1 to 1000 code example
Example: palindrome number in java
import java.util.Scanner;
public class Palindrome
{
public static void main(String args[])
{
int num,temp,reverse=0;
Scanner input=new Scanner(System.in);
num=in.nextInt();
temp=num;
//code to reverse the number
while(temp!=0)
{
int d=temp%10; //extracts digit at the end
reverse=reverse*10+d;
temp/=10; //removes the digit at the end
}
// 'reverse' has the reverse version of the actual input, so we check
if(reverse==num)
{
System.out.println("Number is palindrome");
}
else
{
System.out.println("Number is not palindrome");
}
}
}