ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2023 ICSE Computer Science Paper



Share with a Friend

Solved 2023 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Sum of Single and Double Digit Number in Array Program - ICSE 2023 Computer Science

Question 8

Define a class to accept values in integer array of size 10. Find sum of one-digit number and sum of two-digit numbers entered. Display them separately.


Example:

Input: a[] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1}

Output:

Sum of one-digit numbers: 2 + 4 + 9 + 3 + 1 = 19
Sum of two-digit numbers: 12 + 18 + 25 + 32 + 20 = 107

import java.util.Scanner; class Find{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int a[] = new int[10]; System.out.println("Enter the integers: "); for(int i = 0; i < a.length; i++) a[i] = Integer.parseInt(in.nextLine()); int oneDigit = 0; int twoDigit = 0; for(int i = 0; i < a.length; i++){ int num = Math.abs(a[i]); if(num >= 0 && num <= 9) oneDigit += a[i]; else if(num >= 10 && num <= 99) twoDigit += a[i]; } System.out.println("Sum of one-digit numbers: " + oneDigit); System.out.println("Sum of two-digit numbers: " + twoDigit); } }

Output

 
 OUTPUT 1: 
Enter the integers: 
1
11
2
22
3
33
4
44
5
55
Sum of one-digit numbers: 15
Sum of two-digit numbers: 165


 OUTPUT 2: 
Enter the integers: 
2
12
4
9
18
25
3
32
20
1
Sum of one-digit numbers: 19
Sum of two-digit numbers: 107