forked from Nnamdikeshi/Java2545examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntMathFix.java
More file actions
25 lines (16 loc) · 744 Bytes
/
Copy pathIntMathFix.java
File metadata and controls
25 lines (16 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package week1_variables_if_else;
/**
* Watch out for integer math rounding - potential bug here!
*/
public class IntMathFix {
public static void main(String args[]) {
//Setting one of the variables to a double ensures that the calculation will include the floating point value of the answer.
double numberOfRides = 30;
int daysOfStateFair = 12;
// A state fair fan is planning to go every day, and
// wants to go on all of the rides. How many rides per day?
double ridesPerDay = numberOfRides / daysOfStateFair;
// Now this displays the correct answer.
System.out.println("To go on all of the rides, you need to go on " + ridesPerDay + " rides every day");
}
}