Assertions
Category: Assertions
Author: Benson Limketkai 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. (You may abbreviate them as A, N, or S.) public static int funky(int a, int digit) { int count = 0; <span class="assertionpoint">// Point A while (a != 0) { <span class="assertionpoint">// Point B if (a % 10 == digit) { count++; <span class="assertionpoint">// Point C } else if (count > 0) { count--; <span class="assertionpoint">// Point D } a = a / 10; } <span class="assertionpoint">// Point E return count; }
1) a == 0
2) a % 10 == digit
3) count > 0