Page 300 - Computer science 868 Class 12
P. 300
25 {
26 System.out.print(even[i] + " ");
27 }
28 System.out.print("\nOdd Numbers:");
29 for (i = 0; i < od; i++)
30 {
31 System.out.print(odd[i] + " ");
32 }
33 }
34 }
The output of the preceding program is as follows:
Total Numbers: 2 3 11 45 37 89 54 44 346 86
Even Numbers: 2 54 44 346 86
Odd Numbers: 3 11 45 37 89
9.5 DOUBLE-DIMENSIONAL ARRAY
Double-Dimensional array is also known as two-dimensional array. Unlike, single-dimensional array which contains
only 1 row, the double-dimensional array stores data in a tabular format, thus containing rows and columns.
st
A double-dimensional array uses a combination of rows and columns where the 1 index refers to the row position and
the 2nd index refers to the column position. It is also known as a Double Subscripted Value as it has two subscripts.
Let us see the following example.
C O L U M N S
R 0 1 2 3
O 0 Amit
W 1 Vijay
S 2
The above Two-dimensional (2-D) array of 3 rows and 4 columns is created as shown below.
String name[][]=new String[3][4];
How to refer to the positions in an array is illustrated below with the help of two examples.
1. If we want to print the value Amit, we use:
System.out.println(array[0][0])
2. Similarly, if we want to access the position where Vijay is to be stored, we use:
array[1][2]=Vijay;
Note: In both type of arrays, the subscript value starts from 0.
Similarly, arrays of different data types can be created as discussed below.
298298 Touchpad Computer Science-XII

