Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ov Gee
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic