Exam 4: Conditionals and Loops
Exam 1: Introduction40 Questions
Exam 2: Data and Expressions40 Questions
Exam 3: Using Classes and Objects40 Questions
Exam 4: Conditionals and Loops40 Questions
Exam 5: Writing Classes40 Questions
Exam 6: Graphical User Interfaces40 Questions
Exam 7: Arrays40 Questions
Exam 8: Inheritance40 Questions
Exam 9: Polymorphism39 Questions
Exam 11: Recursion40 Questions
Exam 10: Exceptions40 Questions
Exam 12: Searching and Sorting40 Questions
Exam 13: Trees40 Questions
Exam 14: Introduction to Collections and Stacks40 Questions
Exam 15: Heaps and Priority Queues40 Questions
Exam 16: Graphs40 Questions
Select questions type
Suppose we want to condition an if statement on whether two String objects, referenced by stringOne and stringTwo, are the same. Which of the following is the correct way to achieve this?
(Multiple Choice)
4.8/5
(37)
The following snippet of code will not compile because the second part of the if statement needs to be on the second line.
if(a < b) System.out.println("a is less than b");
(True/False)
4.9/5
(36)
Rewrite the following code fragment using a for loop instead of a while loop.
int i = 0;
while(i < 50) {
System.out.println(i);
i+=2;
}
(Short Answer)
4.8/5
(34)
Which of the following logical operators has the highest precedence?
(Multiple Choice)
4.7/5
(36)
What is wrong with the following snippet of code? Rewrite it so it produces the correct output.
if(a < b)
if(a == c)
System.out.println(“a < b and a == c”);
else
System.out.println(“a is not less than b”);
(Essay)
4.9/5
(40)
Write a code fragment that allows a user to continue inputting numbers until she enters a sentinel value of 0. Then print the sum of all the numbers she entered. You may assume that a Scanner object called input has already been created.
(Essay)
4.8/5
(45)
Which of the following best describes this code snippet?
if (count != 400)
System.out.println("Hello World!");
(Multiple Choice)
4.7/5
(37)
Let a and b be valid boolean expressions. Which of the following best describes the result of the expression a || b?
(Multiple Choice)
4.9/5
(43)
Rewrite the following for loop as a while loop.
for(int i = 0; i < MAX; i++)
//loop body
(Short Answer)
4.8/5
(39)
A logical expression can be described by a ________________ that lists all possible combinations of values for the variables involved in an expression.
(Multiple Choice)
4.8/5
(37)
Write a short application that takes in a String from the user and prints it out backwards.
(Essay)
4.7/5
(45)
It is possible to implement a switch statement using if statements.
(True/False)
4.9/5
(33)
The relational operators should not be used to test the equality of objects.
(True/False)
4.9/5
(40)
Write a for loop to print the even numbers from 1 to 100 (inclusive).
(Short Answer)
4.9/5
(41)
The ___________________ statement causes current iteration of a loop to stop and the condition to be evaluated again, either stopping the loop or causing the next iteration.
(Multiple Choice)
4.8/5
(25)
Which of the following for loop headers will cause the body of the loop to be executed 10 times?
(Multiple Choice)
4.8/5
(40)
A _______________ loop always executes its loop body at least once.
(Multiple Choice)
4.8/5
(39)
Showing 21 - 40 of 40
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)