Assertions
Category: Assertions
Author: Stuart Reges
Book Chapter: 5.5
Problem: Assertions
You will identify various assertions as being either always true, never true or sometimes true/sometimes false at various points in program execution. The comments in the method below indicate the points of interest.
public static void mystery(int x, int y) {
int z = 0;
<span class="assertionpoint">// Point A
while (x < y) {
<span class="assertionpoint">// Point B
z++;
if (z % 2 == 0) {
x *= 2;
<span class="assertionpoint">// Point C
} else {
y--;
<span class="assertionpoint">// Point D
}
}
<span class="assertionpoint">// Point E
System.out.println(z);
}
1) x < y
2) z == 0
3) z % 2 == 0