Page 393 - ComputerScience_Class_11
P. 393
3. public class MatrixExample
{
public static void main(String[] args)
{
int[][] matrix = new int[2][2];
matrix[0] = {1, 2};
matrix[1] = {3, 4};
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.println(matrix[i][j]);
}
}
}
}
Ans. public class MatrixExample {
public static void main(String[] args) {
int[][] matrix = new int[2][2];
matrix[0] = new int [] {1, 2};
matrix[1] = new int [] {3, 4};
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.println(matrix[i][j]);
}
}
}
}
Unsolved Questions
A. Tick ( ) the correct option.
1. Which of the following is the correct statement to declare and initialise an array?
a. int ar[ ] = [3, 5, 7]; b. int[ ] ar = [3, 5, 7];
c. int ar[ ] = {3, 5, 7}; d. int [ ] ar = {3, 5, 7};
2. Binary search is also known as ………………… .
a. Middle search b. Half search
c. Half-interval search d. Middle-interval search
3. We use the array name and the element’s ………………… to access the element.
a. data type b. subscript
c. name d. value
4. Which of the following statements can be used to create a one-dimensional array ar of size 5 with double type values?
a. double [5] ar; b. double [5] = ar;
c. double ar[] = ar[5]; d. double ar[5];
5. The ………………… sort usually performs less interchanges than the ………………… sort.
a. bubble, insertion b. bubble, selection
c. selection, bubble d. selection, insertion
B. Fill in the blanks.
1. Index in an array starts with ………………… .
2. ………………… search is also known as sequential search.
Arrays 391

