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 void mystery(Scanner console) { int x = 0; int y = 1; int next = console.nextInt(); <span class="assertionpoint">// Point A while (next != 0) { <span class="assertionpoint">// Point B y = y * next; if (next < 0) { x++; <span class="assertionpoint">// Point C } next = console.nextInt(); <span class="assertionpoint">// Point D } <span class="assertionpoint">// Point E System.out.println(y + " " + x); }
1) next < 0
2) next == 0
3) x > 0