English

Write a program to check if a number is a numeric palindrome.

Advertisements
Advertisements

Question

Write a program to check if a number is a numeric palindrome.

Code Writing
Advertisements

Solution

import java.util.*;
class clDigits
{
    void main()
    {
        Scanner sc = new Scanner(System.in);
        int N, revn = 0, cn = 0, d = 0;
        
        System.out.print("Enter a number: ");
        N = sc.nextInt();
        cn = N;        
        while(cn > 0)
        {
            d = cn % 10;
            revn = revn * 10 + d;
            cn = cn / 10;
        }        
        if(N == revn)
        {
            System.out.print(N + " is a Numeric Palindrome.");
        }
        else
        {
            System.out.print(N + " is Not a Numeric Palindrome.");
        }
    }
}

Output:

Enter a number : 2332

2332 is a Numeric Palindrome.

Enter a number : 135

135 is Not a Numeric Palindrome.

shaalaa.com
  Is there an error in this question or solution?
Chapter 11: Programs Overall - Digit Handling [Page 252]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 11 Programs Overall
Digit Handling | Q 3. | Page 252
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×