# array question and confusion

Kay Liew

Ranch Hand

Posts: 112

posted 11 years ago

- 0

I got so confused about this array question from KB book. Can someone please explain to me why B is correct and C is wrong ?? I really couldn't see why C is wrong.

A: b2[0][1] = b;

B: b[0][0]= b3;

C: b2[1][1][0]=b[0][0];

D: b2[1][2][0]=b;

E: b[0][1][0][0]=b[0][0];

F: b2[0][1]=big;

Suggested answer is A,B,E,F. B is the one that confused me the most. According to page 32. Wouldn't answer B contradicted with the explaination

below ?

int[][] books = new int [3][1];

int[] numbers = new int[6];

in aNumber = 7;

books[0] = aNumber; //NOT OK, expecting an int array instead of an int

books[0] = numbers; //OK, numbers is an int array.

Thx in advance,

Kay

( tags corrected and typos in code corrected)

[ December 07, 2004: Message edited by: Barry Gaunt ]

A: b2[0][1] = b;

B: b[0][0]= b3;

C: b2[1][1][0]=b[0][0];

D: b2[1][2][0]=b;

E: b[0][1][0][0]=b[0][0];

F: b2[0][1]=big;

Suggested answer is A,B,E,F. B is the one that confused me the most. According to page 32. Wouldn't answer B contradicted with the explaination

below ?

int[][] books = new int [3][1];

int[] numbers = new int[6];

in aNumber = 7;

books[0] = aNumber; //NOT OK, expecting an int array instead of an int

books[0] = numbers; //OK, numbers is an int array.

Thx in advance,

Kay

( tags corrected and typos in code corrected)

[ December 07, 2004: Message edited by: Barry Gaunt ]

Unity can only be manifested by the Binary. Unity itself and the idea of Unity are already two.

Spaceact Wong

Greenhorn

Posts: 27

posted 11 years ago

Hi,...

According to me, B is indeed correct and C is indeed wrong.

B is the normal initialization of the array (in this case) and is the easiest part to be notified as correct answer!!!

At the time you answer the question, did you regard answer 'A' as the correct answer??? I think if you put 'A' as the correct answer, then you should be able to know why C is incorrect, right?

C may only be correct, such as b2[1][1][0][0] = b[0][0];

By the way, is E shd be

- 0

Originally posted by Kay Liew:

I got so confused about this array question from KB book. Can someone please explain to me why B is correct and C is wrong ?? I really couldn't see why C is wrong.

<CODE>

public class Test{

public staic void main(String [] args){

btye [][] big = new byte [7][7];

byte [][] b = new new byte [2][1];

byte b3 = 5;

byte b2 = [][][][] = new byte [2][3][2][2];

}

}

</CODE>

A: b2[0][1] = b;

B: b[0][0]= b3;

C: b2[1][1][0]=b[0][0];

D: b2[1][2][0]=b;

E: b[0][1][0][0]=b[0][0];

F: b2[0][1]=big;

Suggested answer is A,B,E,F. B is the one that confused me the most. According to page 32. Wouldn't answer B contradicted with the explaination

below ?

int[][] books = new int [3][1];

int[] numbers = new int[6];

in aNumber = 7;

books[0] = aNumber; //NOT OK, expecting an int array instead of an int

books[0] = numbers; //OK, numbers is an int array.

Thx in advance,

Kay

Hi,...

According to me, B is indeed correct and C is indeed wrong.

B: b[0][0]= b3;

B is the normal initialization of the array (in this case) and is the easiest part to be notified as correct answer!!!

C: b2[1][1][0]=b[0][0];

At the time you answer the question, did you regard answer 'A' as the correct answer??? I think if you put 'A' as the correct answer, then you should be able to know why C is incorrect, right?

C may only be correct, such as b2[1][1][0][0] = b[0][0];

E: b[0][1][0][0]=b[0][0];

By the way, is E shd be

**b2[0][1][0][0] = b[0][0];**

MCP, MCAD .NET, MDSD .NET, MCDBA (SQL Server 2000) <br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3

Ransika deSilva

Ranch Hand

Posts: 524

posted 11 years ago

- 0

Hi,

Let me explain this to you. Now the answer A is correct. b2 is a 4 dimensional array and b is a 2 dimensional array. There you are assigning a 2d array to b2[0][1]. So the total number of Dimensions are 4. Which makes b2 a 4d array. So that is correct. All you have to remember is that, the number of Dimensions should be the same as to declared once you assign arrays.

Answer B is also correct cause you are just assigning a value (NOT an array) to the 0th location of the 0th row.

Answer C in INCORRECT. The 4th element is an array and NOT a value. But what happens at the Answer C is that it is assigning a value as the 4th Dimension. b2[1][1][0]= b[0][0]; b[0][0] is a value and NOT an array. So now the b2 has only 3 Dimensions, which is WRONG. It should be 4 Dimensions.

Hope you can figure out the rest. Just ask if you need any more clarifications. Cheers.......

Let me explain this to you. Now the answer A is correct. b2 is a 4 dimensional array and b is a 2 dimensional array. There you are assigning a 2d array to b2[0][1]. So the total number of Dimensions are 4. Which makes b2 a 4d array. So that is correct. All you have to remember is that, the number of Dimensions should be the same as to declared once you assign arrays.

Answer B is also correct cause you are just assigning a value (NOT an array) to the 0th location of the 0th row.

Answer C in INCORRECT. The 4th element is an array and NOT a value. But what happens at the Answer C is that it is assigning a value as the 4th Dimension. b2[1][1][0]= b[0][0]; b[0][0] is a value and NOT an array. So now the b2 has only 3 Dimensions, which is WRONG. It should be 4 Dimensions.

Hope you can figure out the rest. Just ask if you need any more clarifications. Cheers.......

SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)