| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
easy
2D Array Main Diagonal
< Prev
Next >

Which line of code should replace the missing code to set the main diagonal elements to 1?

public class Diagonal {
    public static void setDiagonal(int[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            /* missing code */
        }
    }
    public static void main(String[] args) {
        int[][] square = new int[3][3];
        setDiagonal(square);
        System.out.println(square[1][1]);
    }
}
A

matrix[i][i] = 1;

B

matrix[i][0] = 1;

C

matrix[0][i] = 1;

D

matrix[i][matrix.length - 1 - i] = 1;

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy