हिंदी

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

Advertisements
Advertisements

प्रश्न

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

कोड लेखन
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 11: Programs Overall - Digit Handling [पृष्ठ २५२]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
Digit Handling | Q 3. | पृष्ठ २५२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×