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 int mystery(int x) {
int y = 1;
int z = 0;
<span class="assertionpoint">// Point A
while (y <= x) {
<span class="assertionpoint">// Point B
y = y * 10;
z++;
<span class="assertionpoint">// Point C
}
<span class="assertionpoint">// Point D
z--;
<span class="assertionpoint">// Point E
return z;
}
1) y > x
2) z < 0
3) z > 0