Assertions
Category: Assertions
Author: Alan Borning and Dan Grossman
Book Chapter: 5.5
Problem: Assertions
For each of the five points labeled by comments, identify each of the assertions in the table below as either being always true, never true, or sometimes true / sometimes false.
public static int assertionMystery(Scanner console) {
int a = -1;
int b = 0;
int next = console.nextInt();
<span class="assertionpoint">// Point A
while(next != 0) {
<span class="assertionpoint">// Point B
b = Math.max(a, next);
a = next;
<span class="assertionpoint">// Point C
if(a == 42) {
<span class="assertionpoint">// Point D
a++;
}
next = console.nextInt();
}
<span class="assertionpoint">// Point E
return b;
}
1) next == 0
2) a > 0
3) b >= next