Ads Here

Sunday, 31 December 2017

PALINDROME

PALINDROME





Program to check whether number is PALINDROME or not by giving  [DYNAMIC VALUES]

import java.lang.*;
import java.util.*;
public class NumberPalindrome1
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n,temp,rem,rev=0;
System.out.println("enter number");
n=sc.nextInt();
temp = n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(temp==rev)
System.out.print("number is palindrome");
else
System.out.print("number is not palindrome");
}
}


Program to check whether number is PALINDROME or not  by giving [FIXED VALUE]

import java.lang.*;
public class NumberPalindrome2
{
   public static void main(String[] args)
{
   int num = 323, revInt = 0, rem, temp;
   temp = num;
    while( num != 0 )
     {
            rem = num % 10;
            revInt = revInt * 10 + rem;
            num = num/10;
     }

 // palindrome if temp and revInt are equal

        if (temp == revInt)
            System.out.println(temp + " is a palindrome.");
        else
            System.out.println(temp + " is not a palindrome.");
    }
}

No comments:

Post a Comment