0:00

Given the following code segment, what is the value of sum after this code executes?

int[][] matrix = {{1,1,2,2},{1,2,2,4},{1,2,3,4},{1,4,1,2}};

int sum = 0;
int col = matrix[0].length - 2;
for (int row = 0; row < 4; row++)
{
   sum = sum + matrix[row][col];
}
倒数第二列求和。
2

What are the contents of mat after the following code segment has been executed?

int [][] mat = new int [4][3];
for (int row = 0; row < mat.length; row++) {
   for (int col = 0; col < mat[0].length; col++) {
      if (row < col)
         mat[row][col] = 1;
      else if (row == col)
         mat[row][col] = 2;
      else
         mat[row][col] = 3;
   }
}
四行三列矩阵,排除后三个选项。mat[0][1]因为col > row,值为1
2

Given the following code segment, what is the value of sum after this code executes?

int[][] m = {{1,1,1,1},{1,2,3,4},{2,2,2,2},{2,4,6,8}};

int sum = 0;
for (int k = 0; k < m.length; k++) {
    sum = sum + m[m.length-1-k][1];
}
第二列求和,逆序循环不影响结果。
3


陈 欣

AADPS创始人

发表评论