Re: Adding doubles and ints.
What have you tried?
Code :
System.out.println(4.4 + 1);
What does that output?
Why are you bothering with ints? Why not just convert everything to double?
Re: Adding doubles and ints.
I actually didn't know you could do that with the System.out.println command. Sorry, I'm still a bit new at this, I've only known Java for like a month.
Edit
Actually, that wouldn't work if 4.4+1 is part of a bigger expression.
You're right about the doubles though.
Re: Adding doubles and ints.
It has nothing to do with the println method and everything to do with math.
Code java:
int one = 1;
double fourPointFour = 4.4;
double result = fourPointFour + one;
Works just fine too.
Re: Adding doubles and ints.
Quote:
Originally Posted by
SkyAphid
First of all, I hate the fact Java can't just NOT separate the two. It's a bit annoying to keep up with.
The two serve different purposes, and people who really care about memory don't want to use something they don't need. "NOT separating the two" would be a horrible idea.
Re: Adding doubles and ints.
Quote:
It's a bit annoying to keep up with
You will find that a lot in programming.There are Lots of important details to keep up with.
Re: Adding doubles and ints.
Quote:
Originally Posted by
SkyAphid
Actually, that wouldn't work if 4.4+1 is part of a bigger expression.
What the heck are you talking about? 4.4 + 1 will produce 5.4 every single time regardless of where you place it in your code. Unless you have 4.4 + 1 * 3.2 in your expression. That of course would produce a different result due to operator precedence but the result will still be a double and you can still add, multiply, subtract and divide ints and doubles.