ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2017 ICSE Computer Science Paper



Share with a Friend

Solved 2017 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Array Based Program - Largest Number, Smallest Number, Sum of Numbers Program- ICSE 2017 Computer Science

Write a program to input integer elements into an array of size 20 and perform the following operations:

(i) Display the largest number from the array.
(ii) Display the smallest number from the array.
(iii) Display the sum of all the elements of the array.

import java.util.Scanner; class max_min_sum{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int a[] = new int[20]; int large = 0; int small = 0; int sum = 0; System.out.println("Enter 20 integers:"); for(int i = 0; i < a.length; i++){ a[i] = Integer.parseInt(in.nextLine()); if(i == 0){ large = a[i]; small = a[i]; sum = a[i]; } else{ if(large < a[i]) large = a[i]; if(small > a[i]) small = a[i]; sum += a[i]; } } System.out.println("Largest number: " + large); System.out.println("Smallest number: " + small); System.out.println("Sum: " + sum); } }

Output

 
 OUTPUT : 
Enter 20 integers:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Largest number: 20
Smallest number: 1
Sum: 210