Exam 5: Conditionals and Loops
Exam 1: Introduction65 Questions
Exam 2: Data and Expressions77 Questions
Exam 3: Using Classes and Objects58 Questions
Exam 4: Writing Classes56 Questions
Exam 5: Conditionals and Loops37 Questions
Exam 6: More Conditionals and Loops36 Questions
Exam 7: Object-Oriented Design76 Questions
Exam 8: Arrays70 Questions
Exam 9: Inheritance71 Questions
Exam 10: Polymorphism70 Questions
Exam 11: Exceptions68 Questions
Exam 12: Recursion68 Questions
Exam 13: Collections68 Questions
Select questions type
In Java, selection statements consist of the if and if-else statements.
(True/False)
4.8/5
(39)
For the questions below, assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye".
-The expression (done | | s.compareTo(t) < 0) is True.
(True/False)
4.8/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)
4.7/5
(34)
Given the nested if-else structure below, answer questions below.
if (a > 0)
if (b < 0)
x = x + 5;
else
if (a > 5)
x = x + 4;
else
x = x + 3;
else
x = x + 2;
-If x is currently 0, a = 5 and b = 5, what will x become after the above statement is executed?
(Multiple Choice)
4.8/5
(26)
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.9/5
(28)
Given the nested if-else structure below, answer questions below.
if (a > 0)
if (b < 0)
x = x + 5;
else
if (a > 5)
x = x + 4;
else
x = x + 3;
else
x = x + 2;
-If x is currently 0, a = 0 and b = -5, what will x become after the above statement is executed?
(Multiple Choice)
4.9/5
(32)
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) | | ! (a && 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
(37)
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.8/5
(37)
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.9/5
(27)
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.9/5
(30)
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.8/5
(43)
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
(37)
For the questions below, assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye".
-The expression (s.concat(t).length( ) < y) is True.
(True/False)
4.8/5
(37)
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.8/5
(37)
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.7/5
(41)
Given the nested if-else structure below, answer questions below.
if (a > 0)
if (b < 0)
x = x + 5;
else
if (a > 5)
x = x + 4;
else
x = x + 3;
else
x = x + 2;
-If x is currently 0, a = 1 and b = -1, what will x become after the above statement is executed?
(Multiple Choice)
4.9/5
(38)
Showing 21 - 37 of 37
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)