Midterm Review Solution
Midterm Review Solution
System.out.println(arr[2]);
Answer: 9
System.out.println(arr[arr.length - 1]);
Answer: 14
5. Write the instruction to find the length of a one-dimensional array named mylist.
System.out.println(numbers[1] + numbers[3]);
Answer: 30
Output:
3 9 5 -5
3. Declare and initialize a 2×3 integer matrix with the given values:
int[][] matrix = {
{2, 4, 6},
};
int[][] arr = {{10, 20, 30}, {40, 50, 60}, {70, 80, 90}};
System.out.println(arr[2][2]);
System.out.println(arr[1][0]);
Output:
90
40
System.out.println(numbers.length);
System.out.println(numbers[0].length);
Output:
int[][] raggedArray = {
{1, 2, 3},
{4, 5},
{6, 7, 8, 9}
};
Class and Object Basic Questions
1.
Output:
Alice 21
2.
Output:
3.
Output: 2
4.
Output:
10