Palindrome Number

Palindrome number in java: A palindrome number is a number that is same after reverse. For example 545, 151, 34543, 343, 171, 48984 are the palindrome numbers. It can also be a string like LOL, MADAM etc.

 import java.util.*;

class pallinodrome

{      //class pallinodrome opens

    public static void main(String[]args)

    {  //main method opens

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter a no");

        int n=sc.nextInt();//variable n accepts the no

        int r=0,rev=0,k=n;//variable r to extract the digits,variable rev to reverse the no,variable k to store the no

        while(n>0)

        {

            r=n%10;

            rev=(rev*10)+r;

            n=n/10;

        }

        if(k==rev)

        System.out.println(k+" is a pallinodrome no");

        else

        System.out.println(k+" is not a pallinodrome no");

    }//main method closes

}//class closes


No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...