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

Match terminology to definitions. 1.assertion 2. boolean 3. De Morgan\'s Laws 4.

ID: 3836377 • Letter: M

Question

Match terminology to definitions.

1.assertion

2. boolean

3. De Morgan's Laws

4. flag

5. logical operators

6. lookahead

7. robust

8. short-circuited evaluation

Answer Choices

A. rules for negating complex boolean expressions

B. AND, OR, and NOT

C. true or false

D. when second operand of or || is not evaluated

E. can deal with illegal data and user errors

F. a boolean variable used as a control variable

G. testing values before reading them

H. a declaration that is true or false

Part 2

What is printed by the following code?

  

boolean flag = true;

x = 1;

while (flag) {

flag = (x < 3);

x++;

}

System.out.println(x);

A. 1

B. 2

C. 3

D. 4

E. 5

Part 3

Which boolean expression is equivalent to the following?

  

(! (x >= 1 && x <= 10))

A. (x < 1 && x > 10)

B. (x < 1 || x > 10

C. (x <= 1 && x >= 10)

D. (x <= 1 || x >= 10)

Part 4

Which boolean expression is equivalent to the following?

  

(! (x == 1 || x == 2))

A. (x != 1 && x != 2)

B. (x != 1 || x != 2)

C. (x == 1 && x == 2)

D. (x == 1 || x == 2)

Part 4

We want to be sure that the user enters an int. What should replace condition and statement in the following code?

  

Scanner console = new Scanner(System.in);

System.out.print("Enter an int: ");

while (condition) {

statement;

System.out.print("Try entering an int again: ");

}

int a = console.nextInt( );

1. replace condition with

2. replace statement with

Answer Choices

A. console.hasNextInt( )

B. console.nextInt( )

C. console.next( )

D. ! console.hasNextInt( )

Explanation / Answer

Part 1

A. rules for negating complex boolean expressions : De Morgan's Laws

B. AND, OR, and NOT : Logical operators

C. true or false : boolean

D. when second operand of or || is not evaluated: short-circuited evaluation

E. can deal with illegal data and user errors : robust

F. a boolean variable used as a control variable : flag

G. testing values before reading them: lookahead

H. a declaration that is true or false : ASSERTION


Part 2

What is printed by the following code?

D. 4
Explanation 4 is printed because when x becomes 3<3 , flag becomes false and x is incremented by one and then while loop exists

Part 3

Which boolean expression is equivalent to the following?

(! (x >= 1 && x <= 10))
B. (x < 1 || x > 10)

Explanation : It means ~(a and b) => ~a || ~b

Part 4

Which boolean expression is equivalent to the following?

(! (x == 1 || x == 2))


A. (x != 1 && x != 2)


Explanation : It means ~(a or b) => ~a && ~b


Part 5

1. replace condition with : A. console.hasNextInt( )

2. replace statement with B. console.nextInt( )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote