Assertions
Category: Assertions
Author: Jessica Miller
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. (You may abbreviate them as A, N, or S.)
// Reads many integers from Scanner; returns the second smallest
// integer read.
public static int secondSmallest(Scanner console) {
int num = console.nextInt();
int first = num;
int second = num;
<span class="assertionpoint">// Point A
while (num >= 0) {
<span class="assertionpoint">// Point B
if (num < first) {
second = first;
first = num;
<span class="assertionpoint">// Point C
} else if (num < second) {
second = num;
}
<span class="assertionpoint">// Point D
}
num = console.nextInt();
<span class="assertionpoint">// Point E
return second;
}
1) num < 0
2) first < second
3) num >= second