Define a class to accept a number from user and check if it is an EvenPal number or not.

ICSE Class 10 Computer Applications PYQ · 2024 Paper · Section B

5Written · 2024 · Section B · 2024 Paper

Define a class to accept a number from user and check if it is an EvenPal number or not.

(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)

Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even number

Show SolutionHide Solution↓
import java.util.Scanner;

public class KboatEvenPal
{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = in.nextInt();
        int org = num;
        int rev = 0;
        int sum = 0;
        
        while (num > 0) {
            int d = num % 10;
            rev = rev * 10 + d;
            sum += d;
            num /= 10;
        }
        

        if (org == rev && sum % 2 == 0) {
            System.out.println(org + " is an EvenPal number.");
        } else {
            System.out.println(org + " is not an EvenPal number.");
        }
    }
}
BlueJ output of KboatEvenPal.java BlueJ output of KboatEvenPal.java BlueJ output of KboatEvenPal.java
← Previous questionNext question →

Browse the free Computer Applications sample bank