Automation Using Selenium Webdriver

Friday, 29 July 2016

Java Program Palindrom


Given Number palindrome Or not

Palindrome number in Java: A palindrome number is a number such that if we reverse it, it will not change. For example some palindrome numbers examples are 121, 212, 12321, -454. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not. C program for palindrome number is given below.

Example:

                package com.java.exmp;

public class Palindrom {

public static void main(String[] args) {
int r,sum=0,temp;
int n=57575;
        temp=n;
        while(n>0)
{
        r=n%10;
        sum=(sum*10)+r;
        n=n/10;
       
}
        if(temp==sum)
        System.out.println("Palindrom number");
        else
        System.out.println("Not Palindrom number");

}

}

Output:
Palindrom number

No comments:

Post a Comment