‹ Back to the paper
What is the outcome of the following code snippet: public class Test { public static void main( ) {…
What is the outcome of the following code snippet:
public class Test
{
public static void main( )
{
char [ ][ ] matrix = {{'a','b','c'},{'p','q','r'},{'x','y','z'}};
for( int i=0 ; i<3 ; i++)
System.out.print( matrix[i] [1] + " " );
}
}- aa b c
- ba p x
- cp q r
- db q y
Answer
Answer
AICorrect option: d
Answer: (d) b q y.
matrix[i][1] picks the element at column index 1 of row i: for i=0 that is matrix[0][1]='b', for i=1 it is matrix[1][1]='q', and for i=2 it is matrix[2][1]='y', giving "b q y".
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 8.