Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2009, 05:17 PM
Member
 
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
abimaran is on a distinguished road
Send a message via Skype™ to abimaran
Post Java Array Assignments?
Given:
Code:
byte[] array1, array2[];
byte array3[][];
byte[][] array4;
If each array has been initialized, which statement will cause a Compiler Error?

Give me the answer and the reasons. Thanx n advanced!

1) array2 = array1;
2) array2 = array3;
3) array2 = array4;
4) Both 1 & 2.
5) Both 1 & 3.
6) Both 2 & 3.

Last edited by abimaran; 11-04-2009 at 05:21 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-04-2009, 05:25 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
JosAH is on a distinguished road
Default
Homework?

kind regards,

Jos
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-04-2009, 05:26 PM
Member
 
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
abimaran is on a distinguished road
Send a message via Skype™ to abimaran
Default
No, JosAH. I'm preparing for SCJP 6 exam.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-04-2009, 05:34 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
JosAH is on a distinguished road
Default
Originally Posted by abimaran View Post
No, JosAH. I'm preparing for SCJP 6 exam.
Well, count the number of dimensions for each array and see for yourself.

kind regards,

Jos
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-04-2009, 05:36 PM
Member
 
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
abimaran is on a distinguished road
Send a message via Skype™ to abimaran
Default
Can we assign one Dimentional array into 2 - Dimentional array and we've to assign every member of one array to other by using a loop?

Here??

Last edited by abimaran; 11-04-2009 at 05:39 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-04-2009, 05:38 PM
Senior Member
 
Join Date: Aug 2009
Posts: 2,193
Rep Power: 4
r035198x is on a distinguished road
Default
Originally Posted by abimaran View Post
...

Give me the answer and the reasons. Thanx n advanced!

...
What is your answer and what are your reasons?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-04-2009, 05:41 PM
Member
 
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
abimaran is on a distinguished road
Send a message via Skype™ to abimaran
Default
The answer should be within those 6 answers.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-04-2009, 06:00 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
JosAH is on a distinguished road
Default
Originally Posted by abimaran View Post
The answer should be within those 6 answers.
Of course; otherwise you would've gotten lots of replies telling you that the correct answer wasn't in the list. btw, have you been a victim of the ferocious brain eater? Is it still hungry? What do you think the answer is?

kind regards,

Jos
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-04-2009, 06:15 PM
Member
 
Join Date: Nov 2009
Location: Colombo, Sri Lanka
Posts: 22
Rep Power: 0
abimaran is on a distinguished road
Send a message via Skype™ to abimaran
Default
array1 is 1D array and array2, array3, array4 are 2D arrays. In JAVA, declaring an array means it(JAVA) creates a variable with a reference to an array. All arrays are technically 1D arrays, Multi dimensional arrays are arrays of arrays.

So, Can we assign 1D array variable into 2D array variable?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-04-2009, 06:18 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 3,337
Rep Power: 5
JosAH is on a distinguished road
Default
Originally Posted by abimaran View Post
array1 is 1D array and array2, array3, array4 are 2D arrays. In JAVA, declaring an array means it(JAVA) creates a variable with a reference to an array. All arrays are technically 1D arrays, Multi dimensional arrays are arrays of arrays.

So, Can we assign 1D array variable into 2D array variable?
Suppose the first line isn't yelled at by the compiler, what is the second line supposed to do?

Code:
int[][] array2d= new int[42]; // assign a 1d array to a 2d ref.
array[1][1]= 54; // where should this be stored?
kind regards,

Jos
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to transfer 1D array in JAVA to 3D array in C fishwater00 New To Java 0 07-31-2009 06:24 PM
New to java, need a little help with array input black06vfr New To Java 11 04-29-2009 05:46 PM
how to convert a Java array to a java stack? pompeez New To Java 2 08-13-2007 02:41 PM
Help with string and array in java zoe New To Java 1 08-07-2007 06:12 AM
Help with array in java coco New To Java 1 08-06-2007 04:03 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:21 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org