ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Specimen Paper



Share with a Friend

Solved 2024 ICSE Computer Science Specimen Paper

Class 10 - ICSE Computer Science Solved Specimen Papers

Sum of Even & Odd Elements in Array Program - ICSE 2024 Computer Science Specimen Paper

Question 6

Define a class to accept values into a 3 × 3 array and check if it is a special array. An array is a special array if the sum of the even elements = sum of the odd elements.

Example:


A[][] = {{4, 5, 6}, {5, 3, 2}, {4, 2, 5}};

Sum of even elements = 4 + 6 + 2 + 4 + 2 = 18


Sum of odd elements = 5 + 5 + 3 + 5 = 18

import java.util.Scanner; class SpecialArray{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int a[][] = new int[3][3]; int even = 0; int odd = 0; System.out.println("Enter elements:"); for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ a[i][j] = Integer.parseInt(in.nextLine()); if(a[i][j] % 2 == 0) even += a[i][j]; else odd += a[i][j]; } } if(even == odd) System.out.println("Special array"); else System.out.println("Not a special array"); } }

Output

 
 OUTPUT : 
Enter elements:
4
5
6
5
3
2
4
2
5
Special array