File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes array index question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "array index question" Watch "array index question" New topic
Author

array index question

Martin Andersson
Greenhorn

Joined: Jan 17, 2008
Posts: 3
1. class Comp2 {
2. public static void main(String[] args) {
3. float f1 = 2.3f;
4. float[][] f2 = {{42.Of}, {l.7f, 2.3f}, {2.6f, 2.7f}};
5. float[] f3 = {2.7f};
6. Long x = 42L;
7.
if (f3 == f2 [2] ) // f2[2] = ?

8. System.out.println("true");
9. }
10. }

Hello, what value are on index f2[2] = ? thanks for the help (42.Of}, {l.7f, 2.3f}, {2.6f, 2.7f)
Alpesh Vesuwala
Greenhorn

Joined: Jan 16, 2008
Posts: 9
Hi Martin,

f2[2] will have memory address of {2.6f, 2.7f}

and in more details,



and for your question,



will compile fine but results in False.


Alpesh.


Sun Certified Java Programmer<br />Sun Certified Mobile Application Developer
Hasnain Khan
Ranch Hand

Joined: Dec 15, 2007
Posts: 44
Hi,



f3 is pointing to a 1 dimension array and f2[2] is pointing to a 2 dimension array i.e {2.6f, 2.7f}

f2[0] is pointing to {42.Of} 1D Array
f2[1] is pointing to {l.7f, 2.3f} 2D Array
f2[2] is pointing to {2.6f, 2.7f} 2D Array

so the if condition will evaluate to false.

Hope that helped.
Kind Regards.
Hasnain Javed Khan.
Martin Andersson
Greenhorn

Joined: Jan 17, 2008
Posts: 3
thank you guys, it's clear now.
Kishore Kumar
Ranch Hand

Joined: Oct 15, 2007
Posts: 71
Hi,
float[][] f2 = {{42.Of}, {l.7f, 2.3f}, {2.6f, 2.7f}};

f2[0] is pointing to {42.Of} 1D Array of 1 element.
f2[1] is pointing to {l.7f, 2.3f} 1DArray of 2 elements.
f2[2] is pointing to {2.6f, 2.7f} 1D Array of 2 elements.

Hasnain Khan, i am correcting your sentences about the dimentions of the array.
Hasnain Khan
Ranch Hand

Joined: Dec 15, 2007
Posts: 44
Hello kesava,
Thanks for correcting my mistake . I was very sleepy when I was answering the question . My Humblest Apologies for any confusions caused .
Kind regards.
Hasnain Javed Khan.
Gitesh Ramchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 274
Hi Martin,

I would just like to add that, "Array indexing starts from 0".

Thanks,
Gitesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array index question