GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Why will not compile? Troublesome....equality operators & floats involved ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why will not compile? Troublesome....equality operators & floats involved )" Watch "Why will not compile? Troublesome....equality operators & floats involved )" New topic
Author

Why will not compile? Troublesome....equality operators & floats involved )

Ov Gee
Greenhorn

Joined: Jun 03, 2009
Posts: 6

Given:

class Comp2
{

public static void main(String[] args)

{

float f1 = 2.3f;
float[][]f2={{ 42.0f},{ 1.7f, 2.3f},{2.6f, 2.7f}};
float[]f3 ={2.7f} ;
Long x = 42L ;
// insert code here
System.out.println("true");

}

}

1.Why if we insert the code f1 == f2[1][1] it will not compile?

I thought it will check if f1 is equal with 2.3f, which is the f2[1][1] and will print "true"

According to the manual not only that it won't print true, but it won't even compile..

I can't figure out why..


Ov Gee
Greenhorn

Joined: Jun 03, 2009
Posts: 6
Ok, my mistake,

the option was f2[1,1] which is obvious not the same thing with f2[1][1]...

i guess writing the code again and again.... helps...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Well done working it out. When asking for help, it is always worthwhile copying-and-pasting: see this and the other FAQs on that page. Even the tiniest spelling error can cause code to fail, or even worse, to produce incorrect results.
 
GeeCON Prague 2014
 
subject: Why will not compile? Troublesome....equality operators & floats involved )