Question: Identify the various assertions in the following code as being always true, never true, or sometimes true and sometimes false at various points in program

Identify the various assertions in the following code as being always true, never true, or sometimes true and sometimes false at various points in program execution. The comments indicate the points of interest:

public static int mystery (Scanner console, int x) { int y = console.nextInt (); int count = 0; // Point A while (y < x) { // Point B if (y == = 0) { count++; // Point C = console.nextInt (); // Point D // Point E return count;

Categorize each assertion at each point with ALWAYS, NEVER, or SOMETIMES.

public static int mystery (Scanner console, int x) { int y = console.nextInt (); int count = 0; // Point A while (y < x) { // Point B if (y == = 0) { count++; // Point C = console.nextInt (); // Point D // Point E return count;

Step by Step Solution

3.52 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

In computer programming specifically when using the imperative programming paradigm an assertion is a predicate a Booleanvalued function over the state space usually expressed as a logical proposition ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

2079_61d6ac344c899_855306.pdf

180 KBs PDF File

Word file Icon

2079_61d6ac344c899_855306.docx

120 KBs Word File

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!