WorksheetsCMP128 Java Ch. 03 Decisions
Total questions: 10
Worksheet time: 20mins
Name
Class
Date
1.
USE THIS TYPE OF DECISION STATEMENT IF YOU WANT TO EXECUTE ONE SET OF STATEMENTS ON THE TRUE PATH AND AN ALTERNATE SET OF STATEMENTS ON THE FALSE PATH.
a)
if statement (binary bypass)
b)
if else statement (binary choice)
c)
switch statement (multiple choice)
d)
nested if statement
2.
WHICH TYPE OF DECISION STRUCTURE IS THIS?
if (x==10)
{
if (y==20)
{
System.out.println("Coordinates: 10, 20");
}
}
if (x==10)
{
if (y==20)
{
System.out.println("Coordinates: 10, 20");
}
}
a)
Switch
b)
If Else if
c)
If else (binary choice)
d)
Nested If
3.
WHAT DECISION STRUCTURE WORKS BEST IF YOU HAVE MORE THAN TWO POSSIBLE ANSWERS (MULTIPLE CHOICE) TO A QUESTION, AND THOSE ANSWERS CAN BE INTEGER OR CHARACTER BASED?
a)
Nested If Statements
b)
An If statement
c)
A Switch statement
d)
If else if statements
4.
WHAT IS MISSING FROM THIS SWITCH STATEMENT THAT WILL CAUSE ALL STATEMENTS ON EVERY CASE PATH TO EXECUTE ONCE A SUITABLE ANSWER IS CHOSEN?
switch (flavor)
{
case 'V':
cone="Vanilla";
case 'C':
cone="Chocolate";
case 'S':
cone="Strawberry";
default:
cone="Empty";
}
switch (flavor)
{
case 'V':
cone="Vanilla";
case 'C':
cone="Chocolate";
case 'S':
cone="Strawberry";
default:
cone="Empty";
}
a)
The case clause
b)
The break clause
c)
The continue clause
d)
The default clause
5.
WHICH OF THE FOLLOWING IS THE RELATIONAL OPERATOR FOR NOT EQUAL TO?
a)
>=
b)
<>
c)
\=
d)
!=
6.
WHICH OF THE FOLLOWING IS THE LOGICAL OPERATOR FOR AN AND RELATIONSHIP?
a)
!
b)
&&
c)
||
d)
&
7.
WHICH OF THE FOLLOWING STATEMENTS WOULD VALIDLY COMPARE TWO STRINGS FOR ONLY AN EXACT EQUALITY MATCH?
a)
if (myName==yourName)
b)
if (myName.compareTo(yourName))
c)
if (myName.equals(yourName))
d)
if (myName.compareToIgnoreCase(yourName))
8.
WHICH METHOD WOULD ALLOW YOU TO COMPARE TWO STRINGS FOR AN EXACT EQUALITY MATCH REGARDLESS OF WHETHER OR NOT ONE OF THE STRINGS IS ALL CAPITALIZED AND THE OTHER IS ALL LOWERCASE?
a)
if (myName.equals(yourName))
b)
if (myName.equalsIgnoreCase(yourName))
c)
if (myName.compareTo(yourName))
d)
None of the above
9.
WHAT DOES THE FOLLOWING CONDITIONAL EXPRESSION DO?
grandTotal = (itemTaxable == 'Y') ? 10.60 : 10.00;
grandTotal = (itemTaxable == 'Y') ? 10.60 : 10.00;
a)
Process a if statement using shorthand notation
b)
Assign 10.60 to grandTotal if the item is taxable
c)
Assign 10.00 to grandTotal if the item is not taxable
d)
All of the above
10.
Which method allows you to display formatted content on the screen, such that you can control whether or not a numeric value has a decimal point and how many decimal places are allowed?
a)
String.format()
b)
System.out.println()
c)
System.out.printf()
d)
None of these
100 %
