ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Paper



Share with a Friend

Solved 2024 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Even Pal Program - ICSE 2024 Computer Science

Question 5
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 even 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 n = Integer.parseInt(in.nextLine()); int r = reverse(n); int s = sum(n); if(n == r && s % 2 == 0) System.out.println("EvenPal number!"); else System.out.println("Not an EvenPal number."); } public static int reverse(int n){ int rev = 0; for(int i = n; i != 0; i /= 10) rev = rev * 10 + i % 10; return rev; } public static int sum(int n){ int s = 0; for(int i = n; i != 0; i /= 10) s += i % 10; return s; } }

Output

 
 OUTPUT 1: 
Enter the number: 121
EvenPal number! 

 OUTPUT 2: 
Enter the number: 135
Not an EvenPal number.