Code:
Tabular format:
0 1 2 3 4
Columns
R 0 1 2 3 4
o
w 1 “My” “First” “2D” “Array”
s
2 “This” “Is” “Cool” “DS”
Equivalent code:
Or
my2DArray(0,0) = "My"
my2DArray(0,1) = "First"
my2DArray(0,2) = "2D"
my2DArray(0,3) = "Array"
my2DArray(1,0) = "This"
my2DArray(1,1) = " Is"
1
my2DArray(1,2) = "Cool"
my2DArray(1,3) = "DS"
my2DArray(2,0) = "CS"
my2DArray(2,1) = "Is"
my2DArray(2,2) = "Awesome"
my2DArray(2,3) = "field!"
my2DArray(3,0) = "I"
my2DArray(3,1) = "love"
my2DArray(3,2) = "CS"
my2DArray(3,3) = "very much!"
Question 1: Access the string: “Awesome” from 2D array implemented in the previous section.
Solution:
It is located at second row and second column. Hence code statement: my2DArray(2,2)
Solution: All of elements are accessed by inner and outer loop. Code as follows:
Output: