WAP in JAVA to check whether a number is palindrome or not
import java.util.*;
class loop{
public static void main(String args[])
{
int n,k,s=0;
Scanner ob=new Scanner(System.in);
System.out.println("enter the nos:");
n=ob.nextInt();
while(n!=0)
{
k=n%10;
s=((s*10) + k);
n=n/10;
}
if(n==s)
System.out.println("palindrome");
else
System.out.println("not palindrome");
}
}
input:enter the nos:101
ouput:palindrome
class loop{
public static void main(String args[])
{
int n,k,s=0;
Scanner ob=new Scanner(System.in);
System.out.println("enter the nos:");
n=ob.nextInt();
while(n!=0)
{
k=n%10;
s=((s*10) + k);
n=n/10;
}
if(n==s)
System.out.println("palindrome");
else
System.out.println("not palindrome");
}
}
input:enter the nos:101
ouput:palindrome
Comments
Post a Comment