ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2021 ICSE Computer Science Paper



Share with a Friend

Solved 2021 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

EvenPal Program - ICSE 2021 Computer Science

Question 8

Write a program to input a number and check and print whether it is an EvenPal number or not.

The number is said to be an EvenPal number when the number is a palindrome number and the sum of its digits is an even number.

Example:
Number 121 is a palindrome number and the sum of its digits is 1 + 2 + 1 = 4, which is an even number.

Therefore, 121 is an EvenPal number.

import java.util.Scanner; class EvenPal{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the number: "); int num = Integer.parseInt(in.nextLine()); int rev = 0; int sum = 0; for(int i = num; i != 0; i /= 10){ rev = rev * 10 + i % 10; sum += i % 10; } if(num == rev && sum % 2 == 0) System.out.println(num + " is EvenPal"); else System.out.println(num + " is not EvenPal"); } }

Output

 
 OUTPUT 1: 
Enter the number: 121
121 is EvenPal

 OUTPUT 2: 
Enter the number: 151
151 is not EvenPal