Computer Applications
Which of the following contain error ?
- int x[ ] = int[10];
- int[ ] y = new int[5];
- float d[ ] = {1, 2, 3};
- x = y = new int[10];
- int a[ ] = {1, 2}; int b[ ]; b = a;
- int i = new int(10);
Java Arrays
10 Likes
Answer
int x[ ] = int[10];
x = y = new int[10];
int i = new int(10);
Reason — int x[] = int[10];
doesn't contain the 'new' keyword used to initialize an array. The correct statement will be int x[] = new int[10];
In the statement x = y = new int[10];
, 'x' and 'y' are not declared as array variables. The correct statement will be :
int x[] = new int[10];
int y[] = new int[10];
In the statement int i = new int(10);
, 'i' is not declared as array variable and small brackets () are used instead of square brackets []. The correct statement will be int i[] = new int[10];
The remaining statements follow the syntax used for declaring and initializing an array, thus they do not have any error.
Answered By
5 Likes
Related Questions
Which of the following statements are valid array declaration ?
- int number( );
- float average[ ];
- double[ ] marks;
- counter int[ ];
Consider the following code
int number[ ] = new int[5];
After execution of this statement, which of the following are True ?
- number[0] is undefined
- number[5] is undefined
- number[2] is 0
- number.length is 5
Given that
int A[ ] = {35, 26, 19, 76, 58};
What will be value contained in A[3] ?- 35
- 26
- 19
- 76
- 58
Given that
int z[ ][ ] = {{2, 6, 5}, {8, 3, 9}};
What will be value of z[1][0] and z[0][2] ?- 2 and 9
- 8 and 5
- 2 and 5
- 6 and 3