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(Scanner console) { int prev = 0; int count = 0; int next = console.nextInt(); <span class="assertionpoint">// Point A while (next != 0) { <span class="assertionpoint">// Point B if (next == prev) { <span class="assertionpoint">// Point C count++; } prev = next; next = console.nextInt(); <span class="assertionpoint">// Point D } <span class="assertionpoint">// Point E return count; }
1) next == 0
2) prev == 0
3) next == prev