Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Java - Arrays
What will be the output of this code?
int[][] matrix = new int[2][2];
matrix[0][1] = 10;
matrix[1][0] = 20;
System.out.println(matrix[0][1] + matrix[1][0]);
A0
B10
C20
D30
Step-by-Step Solution
Solution:
  1. Step 1: Assign values to matrix elements

    matrix[0][1] = 10 and matrix[1][0] = 20.
  2. Step 2: Calculate sum and print

    Sum is 10 + 20 = 30, which is printed.
  3. Final Answer:

    30 -> Option D
  4. Quick Check:

    Sum of assigned elements = 30 [OK]
Quick Trick: Sum assigned elements, unassigned default to zero [OK]
Common Mistakes:
  • Ignoring default zero values
  • Adding wrong elements
  • Syntax errors in assignment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes