Arrays
ICSE Class 10 · Computer Applications · Chapter 7
What this chapter covers
- What an array is and why it is needed
- Declaring and initialising a single-dimensional array
- Accepting data and accessing elements
- Linear search
- Binary search
- Selection sort
- Bubble sort
- Declaring and initialising a double-dimensional array
- Displaying a double-dimensional array in matrix format
- Sum of rows, columns and diagonals
Key points
- An array is a fixed-size collection of values of one type under one name; each element is reached by an index starting at 0.
- An array is a composite (non-primitive, reference) type; the array variable holds a reference to the elements.
- Declare and create with `type name[] = new type[size];` or initialise with `type name[] = {v1, v2, ...};`.
- Elements created with `new` get default values: 0, 0.0, `'\u0000'`, `false` or `null`.
- Memory used = number of elements × size of one element (`int` 4 bytes, `double` 8, `char` 2).
- `name.length` gives the number of elements; valid indices run from 0 to `length - 1`; any other index throws `ArrayIndexOutOfBoundsException` at run time.
- Linear search checks every element in turn and works on any array; binary search halves a sorted array at each step using `low`, `high` and `mid`.
- Selection sort selects the smallest of the unsorted part and swaps it to the front, with at most one swap per pass.
- Bubble sort compares neighbours and swaps them when out of order, so the largest value moves to the end on each pass.
- Both sorts need n - 1 passes for n elements; a swap needs a temporary variable.
- A double-dimensional array is declared as `type name[][] = new type[rows][cols];`; `name.length` gives the rows and `name[0].length` the columns.
- Use nested loops to read and display a matrix, with `print` for each element and `println()` after each row.
- Row sum: reset before each row and add across columns; column sum: outer loop on columns, inner loop down rows.
- In a square matrix the left diagonal has `i == j` and the right diagonal has `i + j == n - 1`.
Questions answered
Define an array. Why is an array called a composite data type?
Write a statement to (a) declare an array `price` of 20 `double` values and (b) initialise a `char` array with the letters of the word "INDIA".
What is the difference between `length` and `length()`?
How many bytes does `long x[] = new long[15];` occupy, and what is the largest valid index?
What happens when the statement `a[a.length] = 5;` is executed?
Give the output: `int p[] = {2, 7, 1, 8, 2, 8}; int c = 0; for (int i = 0; i < p.length; i++) if (p[i] % 2 == 0) c++; System.out.println(c);`
State two differences between linear search and binary search.
Why does binary search give a wrong result on an unsorted array?
Past board exam questions
ICSE 2026 board paper · 15 marks
Write a program to accept the designations of 100 employees in a single dimensional array. Accept the designation from the user and print the total number of employees with the designation given by the user as input. Example: | Trainee | Manager | Chef | Manager | Director | Manager | |---|---|---|---|---|---| Input: Manager Output: 3
Show answer
ICSE 2026 board paper · 15 marks
Write a program to accept a two-dimensional integer array of order 4 x 5 as input from the user. Check if it is a Sparse Matrix or not. A matrix is considered to be a sparse, if the total number of zero elements is greater than the total number of non-zero elements. Print appropriate messages. Example: | 4 | 3 | 0 | 1 | 0 | |---|---|---|---|---| | 1 | 0 | 0 | 2 | 0 | | 1 | 0 | 1 | 0 | 0 | | 0 | 3 | 2 | 0 | 0 | Number of zero elements = 11 Number of non zero elements = 9 Matrix is a Sparse Matrix
Show answer
ICSE 2026 board paper · 1 mark
An array with 3 elements is arranged in ascending order as follows: [4, 1, 3] → (4 and 1 are swapped) → [1, 4, 3] → (4 and 3 are swapped) → [1, 3, 4] Name the technique used:
- Bubble sort
- Linear Search
- Selection sort
- Binary Search
Show answer
ICSE 2026 board paper · 1 mark
The sales made by 5 salesmen selling 5 products is stored in a two-dimensional array of integer data type. How many bytes does the array occupy?
- 25
- 200
- 50
- 100
Show answer
ICSE 2026 board paper · 2 marks
The following program segment swaps the first element and the second element of the given array without using the third variable, fill in the blanks with appropriate java statements: ``` void swap() { int x[ ] = {4, 8, 19, 24, 15}; (1) __________; (2) __________; x[0] = x[0] / x[1]; System.out.println(x[0]+" "+x[1]); } ```
Show answer
ICSE 2026 board paper · 2 marks
int X[ ][ ] = {{4, 5}, {7, 2}, {19, 4}, {7, 4}}; Write the index of the maximum element and the index of the minimum element of the array.
Show answer
ICSE 2025 board paper · 15 marks
Define a class to accept values into a 4 x 4 integer array. Calculate and print the NORM of the array. NORM is the square root of sum of squares of all elements. | 1 | 2 | 1 | 3 | |---|---|---|---| | 5 | 2 | 1 | 6 | | 3 | 6 | 1 | 2 | | 3 | 4 | 6 | 3 | Sum of squares of elements = 1+4+1+9+25+4+1+36+9+36+1+4+9+16+36+9 = 201 NORM = Squareroot of 201 = 14.177446878757825
Show answer
ICSE 2025 compartment paper · 15 marks
Define a class to accept values into a 3x3 integer array and print the product of each row elements. Example: | 3 | 1 | 2 | |---|---|---| | 4 | 2 | 1 | | 5 | 1 | 2 | Output: Row 0 – 6 Row 1 – 8 Row 2 – 10