wap to accept and check whether the number is palindrome or not
Answers
Answered by
8
import java.until.*;
class prg
{
public static void main(String abc[]);
{
Scanner in= new Scanner(System.in);
int a,b,c,d=0;
System.out.println("Enter a number");
a=c=in.nextInt();
while(c>0)
{
b=c%10;
c/=10;
d=d*10+b;
}
if(a==d)
System.out.println("palindrome");
else
System.out.println("not a palindrome");
}
}
class prg
{
public static void main(String abc[]);
{
Scanner in= new Scanner(System.in);
int a,b,c,d=0;
System.out.println("Enter a number");
a=c=in.nextInt();
while(c>0)
{
b=c%10;
c/=10;
d=d*10+b;
}
if(a==d)
System.out.println("palindrome");
else
System.out.println("not a palindrome");
}
}
Answered by
1
Answer:
import java.util.*;
class Palindrome
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter a number");
int num=sc.nextInt();
int reversedno = 0, remainder, originalno;
originalno = num;
while( num != 0 )
{
remainder = num % 10;
reversedno = reversedno * 10 + remainder;
num /= 10;
}
if (originalno == reversedno)
System.out.println(originalno + " is a palindrome.");
else
System.out.println(originalno + " is not a palindrome.");
}
}
Explanation:
Similar questions