Exam 5: Conditionals and Loops

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

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

Free
(True/False)
4.8/5
(39)
Correct Answer:
Verified

False

String s1 is said to overlap String s2 if all of the characters in s1 also appear in s2. Write a set of code that will set the boolean variable overlap to true if s1 overlaps s2 and false otherwise. Assume both s1 and s2 have already been input.

Free
(Essay)
4.8/5
(38)
Correct Answer:
Verified

boolean overlap = True;
int j = 0;
while (overlap && j < s1.length())
{
boolean found = False;
int k = 0;
while (!found && k < s2.length())
if (s2.charAt(k) == s1.charAt(j))
found = True;
else k++;
if (!found) overlap = False;
j++;
}

In order to compare int, float and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo(), equals()and equalsIgnoreCase().

Free
(True/False)
4.9/5
(37)
Correct Answer:
Verified

False

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\nobreakspace\&\&\nobreakspaceb)\nobreakspace||\nobreakspace!(a\nobreakspace\&\&\nobreakspacec) 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
(42)

Every iterator

(Multiple Choice)
4.8/5
(35)

The following code has a syntax error immediately before the word else. What is the error and why does it arise? Fix the code so that this statement is a legal if-else statement. if (x < 0); x++; else x--;

(Essay)
4.8/5
(33)

Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) Max = total / count;

(Multiple Choice)
4.7/5
(34)

Of the following if statements, which one correctly executes three instructions if the condition is true?

(Multiple Choice)
4.8/5
(23)

The statement: if (a >= b) a++; else b--; will do the same thing as the statement: if (a < b) b--; else a++;.

(True/False)
4.7/5
(38)

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 = 5 and b = 5, what will x become after the statement shown is executed?

(Multiple Choice)
4.8/5
(36)

Which of the following are true about check boxes?

(Multiple Choice)
4.8/5
(35)

Which type of GUI control would be best to use if you wanted the user to select one date from a list of three possible dates to take an exam?

(Multiple Choice)
4.8/5
(44)

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

(True/False)
4.9/5
(31)

What does the break statement do?

(Multiple Choice)
4.8/5
(44)

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

(Multiple Choice)
4.8/5
(38)

If a break occurs within the innermost loop of a nested loop that is three levels deep

(Multiple Choice)
4.8/5
(31)

An if statement may or may not have an else clause, but an else clause must be part of an if statement.

(True/False)
4.9/5
(40)

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?

(Multiple Choice)
4.9/5
(30)

If you create an ArrayList without specifying the type of element, the ArrayList will store Object references which means you can put any type of object in the list.

(True/False)
4.8/5
(39)

The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as

(Multiple Choice)
4.8/5
(31)
Showing 1 - 20 of 38
close modal

Filters

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