Assertions
Category: Assertions
Author: Helene Martin and Marty Stepp
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 mystery(Scanner console, int f) {
int num = console.nextInt();
int h = 0;
<span class="assertionpoint">// Point A
while (f < 5) {
<span class="assertionpoint">// Point B
if (num == 0) {
h = 0;
f++;
<span class="assertionpoint">// Point C
} else {
<span class="assertionpoint">// Point D
h++;
}
num = console.nextInt();
}
<span class="assertionpoint">// Point E
return f;
}
1) h == 0
2) f >= 5
3) num == 0