wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 37938
    
  22
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Why will not compile? Troublesome....equality operators & floats involved )
 
Similar Threads
Comparison of arrays
Compiling errata for K&B, SCJP 6
operator
Quw from KB book, chap 4 -> test Q 3
doubt in kathy sierra question?