wap to accept and check wheather it a palindrome or not by using method void palin(int)
Answers
Answered by
1
Answer:
Program:-
public class Main
{
void palin(int n)
{
int a=0,r=0,num=0;
System.out.println("The entered number:"+n);
num=n;
while(n!=0)
{
a=n%10;
r=r*10+a;
n=n/10;
}
if(r==num)
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
public static void main(String args[])
{
Main ob=new Main();
ob.palin(101);
}
}
The first photo is the output of entered 101.
The second photo is the program if I entered 190.
The third photo is the output for a non-palindrome number.
More information:-
- A palindrome number is a number in which the orignal number and the number formed by reversing the digits are equal. Ex 11,101,111,505 etc
- A function is need to be called by creating the object of the class.
- For input we may write the input in the bluej method call or we can write the value with the function.Like i wrote ob.palin(101).
Attachments:
Similar questions