티스토리 뷰

Given the code fragment:

package ocjap;
public class Arr18 {
public static void main(String[] args) {
/* insert code here */
int array[2];
array[0]=10;
array[1]=20;
System.out.print(array[0]+":"+array[1]);

}

}

Which code fragment, when inserted at line 3, enables the code to print 10:20?

A. int[] array=new int[2];

B. int[] array;

array=int[2];

C. int array=new int[2];

D. int array[2];

 

정답: A

해설:

자바의 배열 선언방법

B번은 아래와 같은 오류가 발생.

The type of the expression must be an array type but it resolved to Class

C번 오류

Type mismatch: cannot convert from int[] to int

D번 오류

Syntax error on token "2", delete this token

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함