File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes x+=a   and x=x+a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "x+=a   and x=x+a" Watch "x+=a   and x=x+a" New topic

x+=a and x=x+a

mantravadi murali

Joined: Jun 06, 2001
Posts: 1
int x;
x = x+0.1;
gives an error.
x += 0.1
doesn't give an error.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Hi, Mantravadi.
You don't get any compilation error in the second case because
x += 0.1;
is equivalent to
x = (int) ( x + 0.1 );
I agree. Here's the link:
subject: x+=a and x=x+a
It's not a secret anymore!