Array-promo

Question

Print Palindrome numbers in given range.

(A palindrome number is a number that remains the same when its digits are reversed.)

				
					Enter the lower range
1
Enter the Upper range
100
Prime Numbers:
1    
2    
3    
4    
5    
6    
7    
8    
9    
11    
22    
33    
44    
55    
66    
77    
88    
99 
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;

public class PalindromeInRange 
{

    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int upperRange=0,lowerRange=0,reversedInteger = 0, remainder, temp=0,i=0;
        
        
        
        System.out.println("Enter the lower range");
        lowerRange=sc.nextInt();
        System.out.println("Enter the Upper range");
        upperRange=sc.nextInt();
        System.out.println("Palindrome Numbers:");
        for(i=lowerRange;i<=upperRange;i++)
        {
            reversedInteger=0;
            if(i>0) 
            {  
                temp= i;

                // reversed integer is stored in variable 
                while( temp != 0 )
                {
                    remainder = temp % 10;
                    reversedInteger = reversedInteger * 10 + remainder;
                    temp =temp/10;
                }

                 /* palindrome if num and reversedInteger are equal*/
                if (i == reversedInteger)
                {
                    System.out.println(i + "    ");
                }
       
            }
        }
    }
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *