Given a starting number and the ending number the task is to find the all the Palindrome Number present in that given range and also to display it’s frequency.
Palindrome Number is a number which is equal to reverse of the itself.
Example 1: 131 if reversed is also 131. Hence it is a Palindrome Number.
Example 2: 123 if reversed is 321. Hence it is not a Palindrome Number.
Java
import java.util.*;
public class PalindromeNumberRange
{
public static void main(String args[])
{
int start=0,end=0,temp=0,frequency=0,rev=0,r=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a starting range: ");
start=sc.nextInt();
System.out.print("Enter a ending range: ");
end=sc.nextInt();
System.out.println("Palindrome Numbers in the given range are:-");
for(int i=start;i<=end;i++)
{
temp=i;
while(temp>0)
{
r=temp%10;
rev=(rev*10)+r;
temp=temp/10;
}
if(rev==i)
{
System.out.println(i);
frequency++;
}
rev=0;
}
System.out.println("Frequency: "+frequency);
}
}Java