
-----------------------------------
Nathan4102
Sat Aug 24, 2013 9:34 pm

FLoat why won't you work???
-----------------------------------
Just playing around with Java, I finally decided I should learn it. Quick question, Why does code A compile, while code B doesn't? Float is a 32 bit decimal, while double is a 64 bit decimal, no? Why can't I use a float here?

Code A:
public class Variables {
    public static void main(String

Code B:
public class Variables {
    public static void main(String

Edit: Screwed up the title... :/

-----------------------------------
DemonWasp
Sat Aug 24, 2013 9:53 pm

RE:FLoat why won\'t you work???
-----------------------------------
When you specify a float literal, it has to end in the letter 'f'. This will compile:


public class Variables { 
    public static void main(String

Your environment should be telling you something about "type mismatch" or "double cannot be converted to float" or "narrowing". In the future, try including the exact error message when asking for help.

-----------------------------------
Nathan4102
Sat Aug 24, 2013 9:56 pm

RE:FLoat why won\'t you work???
-----------------------------------
Hmm... Weird.

Thanks for the help, and I will do in the future

-----------------------------------
Nathan4102
Sun Sep 01, 2013 1:01 pm

RE:FLoat why won\'t you work???
-----------------------------------
Another quick question, I won't bother posting a whole thread just for this. Im trying to use command line arguments, but for some reason, I can't get true when comparing them. Anyone know why?

public class Calculator {
    public static void main (String args

http://i.imgur.com/4LDMBiC.png

Edit:

Fixed it. For some reason, == wouldn't work with strings, but .equals() did.

-----------------------------------
DemonWasp
Sun Sep 01, 2013 4:18 pm

RE:FLoat why won\'t you work???
-----------------------------------
The reason is actually really important.

In Java (but not always other languages), the == operator (for objects, but not primitives) is the "identity" operator. If a == b then a is exactly the same object as b. The equals() method compares the contents of a and b for equality.

The default implementation of equals, in Object.equals(Object), compares by the identity operator. The String class overrides that implementation with an implementation that compares by lexical (string) equality. Other objects may have their own overrides.

-----------------------------------
Nathan4102
Mon Sep 02, 2013 11:18 am

RE:FLoat why won\'t you work???
-----------------------------------
Thats weird, I've always used =/== to compare strings. Thanks for the info!
