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 (x > y) {
<span class="assertionpoint">// Point C
x = x / 10;
} else {
<span class="assertionpoint">// Point D
y = y / 10;
}
}
<span class="assertionpoint">// Point E
System.out.println(x + " " + y + " " + z);
}
1) x > y
2) z == 0
3) x == y