posted 23 years ago
Linda,
None of them above were correct
A int [ ] arr = new int [5] {1, 2, 3, 4, 5}; --> Incorrect
Reason: {1, 2, 3, 4, 5} creates an array and initializes its elements to the specified values.
Corrected form int [ ] arr = new int [] {1, 2, 3, 4, 5};
B int arr [5] = new int [ ] {1, 2, 3, 4, 5}; --> Incorrect
Reason: arr [5] should not have dimention in it.
Corrected form int [ ] arr = new int [] {1, 2, 3, 4, 5};
C int arr [ ] [ ] = new int [5] [ ] {1, 2, 3, 4, 5}; --> Incorrect
Reason: This is a two dimensional array. Initialization should be different
Corrected form int arr [ ] [ ] = new int [ ] [ ] {{1, 2, 3, 4, 5},{1,2,3,4,5}};
D int arr [ ] [ ] = new int [5] [5] {{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5}}; -->Incorrect
Reason: If you define size don't initialize with {{1, 2, 3, 4, 5},
{1, 2, 3, 4, 5}};
Corrected form : Either remove size or initialization
int arr [ ] [ ] = new int [] []{{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}};
or
int arr [ ] [ ] = new int [5] [5];
E int [ ] arr [ ] = new int [25]; --> Incorrect
Reason: In compatible declaration
Corrected form:
int [ ] arr = new int [25];
or
int arr [ ] = new int [25]
[This message has been edited by venu gopal (edited January 19, 2001).]