Reputation: 129
I'm making some calculations on my project in order to see how many trucks could be parked on a road of X meters.
I have this:
int road1 = 140;
double trucks = 0;
trucks = (road1-10)/20;
System.out.println("trucks"+trucks);
The problem is that if you calculate by yourself, the result will be 6.5. So you could park 6.5 trucks.
But I always get 6.0
Upvotes: 1
Views: 135
Reputation: 1388
You are doing the calculation with ints, if you change to trucks = (road1-10)/20.0
you will get the answer 6.5
Upvotes: 4