Exam 5: Conditionals and Loops

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

How many times will the following loop iterate? int x = 10; While (x > 0) { System.out.println(x); X--; }

(Multiple Choice)
4.7/5
(44)

Code Segment Ch 05-1 if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; -Refer to Code Segment Ch 05-1. If x is currently 0, a = 1 and b = -1, what will x become after the statement shown is executed?

(Multiple Choice)
4.7/5
(30)

As in the other members of the C family of languages (C, C++, C#), Java interprets a zero value as false and a non-zero value as true.

(True/False)
4.8/5
(35)

Rewrite the following set of if statements using a nested if-else structure. if (score >= 90) grade = 'A'; if (score >= 80 && score < 90) grade = 'B'; if (score >= 70 && score < 80) grade = 'C'; if (score >= 60 && score < 70) grade = 'D'; if (score < 60) grade = 'F';

(Essay)
4.9/5
(34)

In Java, selection statements consist only of if and if-else statements.

(True/False)
4.8/5
(41)

What is wrong, logically, with the following code? if (x > 10) System.out.println("Large"); Else if (x > 6 && x <= 10) System.out.println("Medium"); Else if (x > 3 && x <= 6) System.out.println("Small"); Else System.out.println("Very small");

(Multiple Choice)
4.9/5
(41)

Consider the following outline of a nested if-else structure which has more if clauses than else clauses. Which of the statements below is true regarding this structure? if (condition1) If (condition2) Statement1; Else Statement2;

(Multiple Choice)
5.0/5
(35)

The statement {} is a legal block.

(True/False)
4.7/5
(33)

Consider the following code that will assign a letter grade of 'A', 'B', 'C', 'D', or 'F' depending on a student's test score. if (score >= 90) grade = 'A'; If (score >= 80) grade = 'B'; If (score >= 70) grade = 'C'; If (score >= 60) grade = 'D'; Else grade = 'F';

(Multiple Choice)
4.7/5
(42)

Explain what is meant by short circuiting and provide an example of short circuiting a condition with && and provide an example of short circuiting a condition with ||.

(Essay)
4.9/5
(38)

Assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye". Then the expression (!done && x <= y) is true.

(True/False)
4.8/5
(33)

Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions: Condition 1: (x < y && x > 0) Condition 2: (a != d || x != 5) Condition 3: !(true && false) Condition 4: (x > y || a == 'A' || d != 'A')

(Multiple Choice)
4.9/5
(44)

Regarding the Software Failure: The operators were warned that, although the Therac-25 had many safety precautions, it might be possible to accidentally overdose a patient.

(True/False)
4.7/5
(42)

Code Segment Ch 05-1 if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; -Refer to Code Segment Ch 05-1. If x is currently 0, a = 0 and b = -5, what will x become after the statement shown is executed?

(Multiple Choice)
4.8/5
(27)

A truth table shows, for the various true or false values of boolean variables, what the result of a boolean condition is. Fill in the following truth table. Assume that a, b and c are boolean variables. a b c a \&\& (!b || c ) false false false false false true false true false false true true true false false true false true true true false true true true

(Essay)
4.8/5
(34)

If x is an int where x = 0, what will x be after the following loop terminates? while (x < 100) X *= 2;

(Multiple Choice)
4.9/5
(32)

As introduced in the Software Failure, the terminology "risk analysis" means

(Multiple Choice)
5.0/5
(40)

In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).

(True/False)
4.9/5
(42)
Showing 21 - 38 of 38
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)