COSC 110 Exam Questions and Answers Graded A+
What would be the results of the following code?
int[] x = { 55, 33, 88, 22, 99,
11, 44, 66, 77};
int a = 10;
if(x[a] > x[5])
a = 5;
else
a = 8; - Answers a = 5
What would be the results after the following code was executed?
int[] x = {23, 55, 83, 19};
int[] y = {36, 78, 12, 24};
for (int a = 0; a < x.length; a++)
{
x[a] = y[a];
y[a] = x[a];
} - Answers x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
Which of the following is a valid declaration for a ragged array? - Answers C. int [][] array1 = new int [5]
[];
What is the value of scores [1][3] in the following array?
int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}
{98, 95, 92, 94}, {91, 84, 88, 96} }; - Answers 80
What is the value of scores [3][2] in the following array?
int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}
{98, 95, 92, 94}, {91, 84, 88, 96} }; - Answers 88
What is the value of scores [1][1] in the following array?
, int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}
{98, 95, 92, 94}, {91, 84, 88, 96} }; - Answers 84
What is the value of scores [3][3] in the following array?
int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}
{98, 95, 92, 94}, {91, 84, 88, 96} }; - Answers 96
What is the output of the following code?
int[][] array2 = { {1, 2}, {3, 4}, {5, 6} };
int sum = 0;
for (int i = 0; i < array2.length; i++)
sum += array2 [i][0];
System.out.println(sum); - Answers 9
Given the following array declaration:
int[][] triangleArray = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9},
{10, 11, 12},
{13, 14},
{15},
};
What is the value of the following triangleArray [1][1]? - Answers 7
Given the following array declaration:
int[][] triangleArray = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9},
{10, 11, 12},