Answers for "number is palidrome in java example"

1

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");
    }
  }
}
Posted by: Guest on August-20-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language