Given the code fragment:
Which code fragment, when inserted at line 3, enables the code to print 10:20?
A.
int[] array n= new int[2];
B.
int[] array;
array = int[2];
C.
int array = new int[2];
D.
int array [2] ;
Given the code fragment:
Which code fragment, when inserted at line 3, enables the code to print 10:20?
A.
int[] array n= new int[2];
B.
int[] array;
array = int[2];
C.
int array = new int[2];
D.
int array [2] ;
B.
int[] array;
array = new int[2];
C.
int[] array = new int[2];
A and B. C is not an array
Answer: A (if int[]array = new int[2]; thus without n)
package q090;
public class Test {
public static void main(String[] args) {
/* insert code*/
int[] array = new int[2]; // without n
//int[] array;
//array = int[2];
//int array = new int[2];
//int array[2];
array[0] = 10;
array[1] = 20;
System.out.print(array[0] +” “+ array[1]);
}
}
/*Output:
10 20
*/
There is a typo in the given answers. I did the exam and passed, this question also came and the right answer is c: int[] array = new int[2];
If answer C is: int[] array = new int[2];, then C is the correct answer.
Thank you.