About Question enthuware.ocajp.i.v7. 2 .1380 :
Moderator: admin
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
About Question enthuware.ocajp.i.v7. 2 .1380 :
Dont understand the difference between,
{{0, 1}, {2, 3}, {4, 5}};
and
{ { {0, 1}, {2, 3}, {4, 5} } };
{{0, 1}, {2, 3}, {4, 5}};
and
{ { {0, 1}, {2, 3}, {4, 5} } };
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
To start with, did you notice the difference in number of opening and closing brackets?
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Yes, syntactically, they are different.
So, does that mean to separate dimensions in arrays, we require {}?
So, does that mean to separate dimensions in arrays, we require {}?
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Yes, try this - http://stackoverflow.com/questions/1067 ... ay-in-java
BTW, your question is too basic. You should first read a book to learn the basics and then attempt the mock exams. Otherwise, it will not help you much.
BTW, your question is too basic. You should first read a book to learn the basics and then attempt the mock exams. Otherwise, it will not help you much.
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
kindly explain "int[][] arr2 = {arr, {1, 2}, arr};"
how is this valid?
how is this valid?
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Again, it is quite basic. You need to go through a book and read a chapter on arrays.
It is not really possible to explain the whole chapter in a post here. Briefly, arr2 is a two dimensional array of ints, so each element of arr2 must be a one dimensional array of ints, which is what {arr, {1, 2}, arr} is doing.
It is not really possible to explain the whole chapter in a post here. Briefly, arr2 is a two dimensional array of ints, so each element of arr2 must be a one dimensional array of ints, which is what {arr, {1, 2}, arr} is doing.
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Understood.
Its array of array we are looking at.
We say its 2D array, and elements are 1D.
"," separates each element.
So, the above mentioned elements form only one part of aoa.
But, {1,2}, whats that?
AND
hows {arr, {1, 2}, arr} different from {{0, 1}, {2, 3}, {4, 5}}
Its array of array we are looking at.
We say its 2D array, and elements are 1D.
"," separates each element.
So, the above mentioned elements form only one part of aoa.
But, {1,2}, whats that?
AND
hows {arr, {1, 2}, arr} different from {{0, 1}, {2, 3}, {4, 5}}
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Please go through the link I gave you above. Read all the answers there.
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Have gone thru the link multiple times but haven't been able to understand hows {arr, {1, 2}, arr} different from {{0, 1}, {2, 3}, {4, 5}}!
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
What kind of difference are you looking for?
In the initialization part of arr2, each element of arr2 has to be either a reference to a one dimensional array of ints or a definition of another one dimensional array itself. arr is a reference to a 1 dimensional array and {0, 1} is just another one dimensional array. So what is the problem?
In the initialization part of arr2, each element of arr2 has to be either a reference to a one dimensional array of ints or a definition of another one dimensional array itself. arr is a reference to a 1 dimensional array and {0, 1} is just another one dimensional array. So what is the problem?
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
Then why is {{0, 1}, {2, 3}, {4, 5}} invalid
and {arr, {1, 2}, arr} valid?
and {arr, {1, 2}, arr} valid?
-
- Site Admin
- Posts: 10058
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1380 :
You need to read the explanation. It explains exactly the question that you are asking.
{{0, 1}, {2, 3}, {4, 5}} can't be assigned to array3D because {{0, 1}, {2, 3}, {4, 5}} is only a two dim array.
The statement int[][] arr2 = {arr, {1, 2}, arr}; is valid because {arr, {1, 2}, arr} is a two dim array and arr2 is variable of type 2d array of ints.
{{0, 1}, {2, 3}, {4, 5}} can't be assigned to array3D because {{0, 1}, {2, 3}, {4, 5}} is only a two dim array.
The statement int[][] arr2 = {arr, {1, 2}, arr}; is valid because {arr, {1, 2}, arr} is a two dim array and arr2 is variable of type 2d array of ints.
If you like our products and services, please help us by posting your review here.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7. 2 .1380 :
Thanks and sorry to bother.
Now, I understand more.
Now, I understand more.
Who is online
Users browsing this forum: Bing [Bot] and 65 guests