Write a program in Java to print all the PALINDROME numbers in the range between m and n
(both inclusive). The input contains two positive integers m and n, where m<n and m<3000 and
n<3000.
[Note: A Palindrome number is a number whose reverse is equal to the original number.]
Answers
Answered by
19
Answer:
package Programmer;
import java.util.*;
public class Palindrome
{
public static void main (String ar [])
{
Scanner sc=new Scanner (System.in);
System.out.println("Enter range (initial and final respectively)");
int m=sc.nextInt();
int n=sc.nextInt();
int I,r=0;
if((m<3000)&&(n<3000))
{
for(I=m;I<=n;I++)
{
int k=I;r=0;
while(k!=0)
{
r=r*10+(k%10);
k/=10;
}
if(r==I)
System.out.println("Palindrome:"+I);
}
}
else
System.out.println("Number is greater than 3000");
}
}
Variable Description:-
- I:- loop variable
- k:- to make copy of variable I
- r:- to store reverse of the number
- m&n:- limit variable
___
•Output Attached
Attachments:
Similar questions