write a programme in java to input any no. and check whether a no. is palendrome or not by using a while loop
Answers
Answer:
Explanation:
class PalindromeExample{
public static void main(String args[]){
int r,sum=0,temp;
int n=454;//It is the number variable to be checked for palindrome
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
}
Question:-
Write a program in Java to input a number and check whether it is Palindrome or not using while loop.
Program:-
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a, b, s=0;
System.out.print("Enter a number: ");
a=sc.nextInt();
b=a;
while(b!=0)
{
s=s*10+b%10;
b/=10;
}
if(s==a)
System.out.println("Number is Palindrome.");
else
System.out.println("Number is not Palindrome.");
}
}