Coding Fun Java Java Program – Checking for Palindrome

Java Program – Checking for Palindrome





A Java Program to check if the given number is a Palindrome or not.
A Palindrome is a string (or a number) who’s reverse is same as the original.

For eg: 4597954
Reverse : 4597954

Tags: , , , , , , , , , ,

6 thoughts on “Java Program – Checking for Palindrome”

  1. loyd rego says:

    good job…………………………

  2. public static void main(String[] args)
    {
    Scanner s=new Scanner(System.in);

    int last_digit;
    int reverse_no=0;
    int original_no=num;
    System.out.println("Enter the no");
    int num=s.nextInt();
       
    while(num > 0)
    {
    last_digit=num%10;
    //System.out.println("last digit:n"+last_digit);

    num=num/10;
    //System.out.println("Truncated no is:n"+num);

    reverse_no = reverse_no * 10 + last_digit;
    //System.out.println("Reversed no is:n"+reverse_no);

    //System.out.println("n");
    }
    if (reverse_no == original_no)

    System.out.println("pal");

    else
    {
    System.out.println("not pal");
    }
    }

    This is my program but when i execute the above program for whatever no it says not palindrome. and even i changed reverse_no == original_no; i ll get the error here original_no=num <– plz reply for this post

  3. NJ says:

    hey wt's the difference of using TEXTMATE for mac? even u can easily do it with TEXTEDIT which is inbuilt support in it ?
    i want to know what exactly is we are trying to achieve by editing in textmate rather than textedit.
    P.S- how to compile in textmate..i run by cmd+r but the error shows up.. do we have 2 do it with terminal?

    Please Do Reply

Leave a Reply

Your email address will not be published. Required fields are marked *