Page 1 of 1

About Question enthuware.ocajp.i.v7.2 . 1191 :

Posted: Tue Mar 20, 2012 10:28 am
by ETS User
I didn't understand this one. Can anyone help me figure out what happened?

Thanks

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Tue Mar 20, 2012 11:03 am
by admin
What is it that you are not able to understand? If you give some details, we can help you out :)

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Tue Mar 20, 2012 11:31 am
by Guest
admin wrote:What is it that you are not able to understand? If you give some details, we can help you out :)
Thanks for quick reply.
char cA[][] = new char[3][];
for (int i=0; i<cA.length; i++) cA = new char[4];
This question says that this array refers to a valid element cA[3][2], but it didn't create the second dimensio of the array. My question is: when I do such a thing, can I access any range of elements in the second brackets?

Thanks

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Tue Mar 20, 2012 11:40 am
by admin
It is creating both the dimensions. It creates the first dimension, when it does new char[3][]; Since the first dimension is an array of arrays, all the elements are initialized to null.

Now, for each element in this array, it assigns: cA = new char[4]; This is the second dimension. It changes the original null references to a new char arrays.

Since the second dimension an array of primitives (char is a primitive data type), all elements of this second array are already initialized to 0.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Sun Mar 25, 2012 2:54 pm
by Matheus
I think that this question was modified, because now the question asks to select an option that create an array of size cA[2][3] and says that this one is the correct answer:
char cA[][] = new char[3][];
for (int i=0; i<cA.length; i++) cA = new char[4];

isn't this one:
char[][] cA = { { 'a', 'b', 'c' }, { 'a', 'b', 'c' } };
AND
char cA[][] = { new char[ ]{ 'a', 'b', 'c' } , new char[ ]{ 'a', 'b', 'c' } };
??

Thanks

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Sun Mar 25, 2012 2:55 pm
by Matheus
Sorry, I misunderstood this question

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Fri Mar 08, 2013 3:48 pm
by baptize
Matheus wrote:Sorry, I misunderstood this question
exactly what i did :x
Hopefully i would pay more attention in the exam....

Mistake question 39 on enthuware.ocajp.i.v7.2.1191 :

Posted: Wed Feb 18, 2015 9:53 pm
by rodrigocesar
Hi everyone,

I've found a mistake on what the software says it's the correct answer of this question:
Which of the following code fragments will successfully initialize a two-dimensional array of chars named cA with a size such that cA[2][3] refers to a valid element?

Code: Select all

1.   char[][] cA = {  { 'a', 'b', 'c' },  { 'a', 'b', 'c' }   }; 

2.   char cA[][] = new char[3][];   for (int i=0; i<cA.length; i++) cA[i] = new char[4]; 

3.   char cA[][] = { new char[ ]{ 'a', 'b', 'c' }  ,   new char[ ]{ 'a', 'b', 'c' }  }; 

4   char cA[3][2] = new char[][] {  { 'a', 'b', 'c' },   { 'a', 'b', 'c' }   }; 

5.   char[][] cA = { "1234", "1234",  "1234"  }; 
Explanation
1 and 3 declare a two dimensional array alright but they create the array of size 2, 3. And cA[2][3] means we need an array of size 3, 4 because the numbering starts from 0.
4 : You cannot put array size information on LHS.
5 : This is a one dimensional array and that too of strings. Note that a java String is not equivalent to 1 dimensional array of chars.
This leaves us with only one choice 2.
This is incorrect! The question asks which options will create a multi-dimensional array of char with a size such that cA[2][3], and options 1 and 3 already do that! If you put the codes (1 and 3) and then run on Java, typing an extra line: System.out.println(cA.length +" "+ cA[0].length), the console will display 2 3, which is the options 1 and 3.

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Thu Feb 19, 2015 2:55 am
by admin
The answer is correct. Please read the explanation carefully.

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Sat Feb 28, 2015 3:24 pm
by rodrigocesar
I'm sorry, but I still think this question has ambiguity, since if you test on console System.out.println(cA.length +" "+ cA[0].length), it's gonna print 2 and 3, so, this answer is correct too.

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Sat Feb 28, 2015 8:33 pm
by admin
The question is NOT asking you to create an array of size 2 and 3. Please read the problem statement carefully.

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Tue Mar 31, 2015 6:09 am
by Sergiy Romankov
I also believe that this question is ambiguos

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Tue Mar 31, 2015 7:10 am
by admin
Sergiy Romankov wrote:I also believe that this question is ambiguos
And why do you think so?

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Wed Apr 01, 2015 7:08 am
by Sergiy Romankov
when I write new int[2][3], I allocate array with TWO elements, which are itself arrays and stored THREE elements each. So in question create multi-array with size [2][3]. What I miss?

Re: About Question enthuware.ocajp.i.v7.2.1191 :

Posted: Wed Apr 01, 2015 7:31 am
by admin
The question is NOT asking you to create an array of size 2 and 3. Please reread the question.