If/Else Simulation
Category: Simulation
Author: Stuart Reges
Book Chapter: 4.1
Problem: If/Else Simulation
Consider the following method.
public static void ifElseMystery(int a, int b) {
if (a == b) {
b--;
} else if (a < b) {
a++;
} else {
b = b + 5;
}
if (a == b) {
a = a + 2;
}
System.out.println(a + " " + b);
}
For each call below, indicate what output is produced.
1) ifElseMystery(14, 14);
2) ifElseMystery(4, 5);
3) ifElseMystery(10, 5);
4) ifElseMystery(2, 8);