‹ Back to the paper
Question 8
1 mark
Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)MCQArrays, Strings
Choose the correct option.
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] + " " );
}
}- (a)a b c
- (b)a p x
- (c)p q r
- (d)b q y
Answer
Answer
Correct 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".