Assertions
Category: Assertions
Author: Marty Stepp and Helene Martin
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(int a) { int b = 0; int c = 0; <span class="assertionpoint">// Point A while (a != 0) { <span class="assertionpoint">// Point B c = a % 10; if (c % 2 == 0) { b++; } else { b = 0; <span class="assertionpoint">// Point C } a = a / 10; <span class="assertionpoint">// Point D } <span class="assertionpoint">// Point E return b; }
1) a != 0
2) c % 2 == 0
3) b > 0