Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSS142 Sample Assertions Problems (handout from the UW) 1. Assertions. You will

ID: 3858114 • Letter: C

Question

CSS142 Sample Assertions Problems (handout from the UW) 1. Assertions. You will identify various assertions as being either alwaystrue, never true or sometimes true/sometimes false at various points inprogram execution. The comments in the method below indicate the pointsof interest. public static void mystery(int x, int y) int z = 0; // Point A while (x >= y) { // Point B // Point C // Point D // Point E System.out.println (z+"" Fill in the table below with the words ALWAYS, NEVER or SOMETIMES Point A Point B Point C Point D Point E SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT SELECT 2. Assertions. You will identify various assertions as being either alwaystrue, never true or sometimes true/sometimes false at various points inprogram execution. The comments in the method below indicate the pointsof interest. //pre : y >= 0 // post: returns xy public static int pow(int x, int y int prod 1; // Point A while [y > 0) { // Point B // Point c x=x*x; // Point D // Point E else prod = prod * x; // Point F // Point G // Point H return prod;

Explanation / Answer

QUESTION 1)

Question 2)

x<y x==y z==0 POINTA sometimes sometimes always POINTB NEVER sometimes sometimes POINTC sometimes sometimes sometimes POINTD sometimes sometimes NEVER POINTE always NEVER sometimes