About Question enthuware.ocajp.i.v7.2 . 1191 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2 . 1191 :
I didn't understand this one. Can anyone help me figure out what happened?
Thanks
Thanks
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
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 :
Thanks for quick reply.admin wrote:What is it that you are not able to understand? If you give some details, we can help you out
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
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
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.
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 :
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
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
-
- Posts: 32
- Joined: Wed Mar 14, 2012 5:45 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
exactly what i didMatheus wrote:Sorry, I misunderstood this question

Hopefully i would pay more attention in the exam....
-
- Posts: 2
- Joined: Wed Feb 18, 2015 9:29 pm
- Contact:
Mistake question 39 on enthuware.ocajp.i.v7.2.1191 :
Hi everyone,
I've found a mistake on what the software says it's the correct answer of this question:
Explanation
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" };
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.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.
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
The answer is correct. Please read the explanation carefully.
-
- Posts: 2
- Joined: Wed Feb 18, 2015 9:29 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
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.
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
The question is NOT asking you to create an array of size 2 and 3. Please read the problem statement carefully.
-
- Posts: 31
- Joined: Thu Feb 19, 2015 8:25 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
I also believe that this question is ambiguos
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
And why do you think so?Sergiy Romankov wrote:I also believe that this question is ambiguos
-
- Posts: 31
- Joined: Thu Feb 19, 2015 8:25 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
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?
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1191 :
The question is NOT asking you to create an array of size 2 and 3. Please reread the question.
Who is online
Users browsing this forum: Bing [Bot] and 10 guests