Deck 5: Decisions

Full screen (f)
exit full mode
Question
Assuming that a user enters 15 as input, what is the output of the following code snippet? <strong>Assuming that a user enters 15 as input, what is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)The number is LARGE! C)The number is SMALL! D)The number is LARGE! The number is SMALL! <div style=padding-top: 35px>

A)There is no output due to compilation errors.
B)The number is LARGE!
C)The number is SMALL!
D)The number is LARGE!
The number is SMALL!
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following statements is true about the if statement?

A)The if statement can have only one condition that evaluates to an integer value.
B)The if block is optional.
C)The else block is optional.
D)The if and else blocks should always be included within curly braces.
Question
A store provides 10 percent discount on all items with a price of at least $100.No discount is otherwise applicable.Which of the following DOES NOT correctly compute the discount?

A) double discount =0;
if ( price >=100)
{
discount =0.10^{*} price;
}
B) double discount =0.10 * price;
if ( price <=100)
{
discount =0;
}
C) double discount;
if (price <100 )
{
discount =0;
}
else
{
discount =0.10* price;
}
D) double discount =10;
if ( price >=100)
{
discount =0.1 * price;
}
else
{
discount =0;
}
Question
Consider the following code snippet.What is the potential problem with the if statement? <strong>Consider the following code snippet.What is the potential problem with the if statement?   </strong> A)Using == to test the double variable average for equality is error-prone. B)The conditional will not evaluate to a Boolean value. C)The assignment operator should not be used within an if-statement conditional. D)Literals should never be used in if statement conditionals. <div style=padding-top: 35px>

A)Using == to test the double variable average for equality is error-prone.
B)The conditional will not evaluate to a Boolean value.
C)The assignment operator should not be used within an if-statement conditional.
D)Literals should never be used in if statement conditionals.
Question
What is the best way to improve the following code fragment? <strong>What is the best way to improve the following code fragment?   </strong> A)Move the duplicated code outside of the if statement B)Shorten variable names C)Move the brackets to save several lines of code D)Add semicolons after the if condition and the else reserved word <div style=padding-top: 35px>

A)Move the duplicated code outside of the if statement
B)Shorten variable names
C)Move the brackets to save several lines of code
D)Add semicolons after the if condition and the else reserved word
Question
What is the output of the following code snippet?

<strong>What is the output of the following code snippet?    </strong> A)Minimum income requirement is not met. B)Maximum income limit is exceeded. C)Income requirement is met. D)There is no output. <div style=padding-top: 35px>

A)Minimum income requirement is not met.
B)Maximum income limit is exceeded.
C)Income requirement is met.
D)There is no output.
Question
Assuming that the user provides 99 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 99 as input, what is the output of the following code snippet?   </strong> A)a: 0 B)a: 99 C)a: 100 D)a: 300 <div style=padding-top: 35px>

A)a: 0
B)a: 99
C)a: 100
D)a: 300
Question
Which of the following is the correct syntax for an if statement?

A) if (x<10) {size = "Small"; }
else (x<20) {size = "Medium"; }
B) if (x<10) ;{ size =" Small"; }
else (x<20) {size = "Medium"; }
C) if (x<10) {size =" Sma11 " ;}
else { size = "Medium";}
D) if { size ="Small"; }
else (x<20) {size = "Medium"; }
Question
What kind of operator is the <= operator?

A)Ternary
B)Arithmetic
C)Inequality
D)Relational
Question
Suppose one needs an if statement to check whether an integer variable pitch is equal to 440 (which is the frequency of the note "A" to which strings and orchestras tune).Which condition is correct?

A)if (pitch - 440 = 0)
B)if ((pitch !< 440) && (pitch !> 440))
C)if (pitch = 440)
D)if (pitch == 440)
Question
Which statement about an if statement is true?

A)The condition in an if statement using relational operators will evaluate to a Boolean result
B)The condition in an if statement should make exact comparisons to floating-point numbers
C)The condition in an if statement should always evaluate to true
D)The condition in an if statement should never include integer variables
Question
What is the output of the following code snippet if the input is 25? <strong>What is the output of the following code snippet if the input is 25?   </strong> A)24 B)25 C)26 D)27 <div style=padding-top: 35px>

A)24
B)25
C)26
D)27
Question
Assuming that the user provides 303 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 303 as input, what is the output of the following code snippet?   </strong> A)x: 0 B)x: 300 C)x: 303 D)There is no output due to compilation errors. <div style=padding-top: 35px>

A)x: 0
B)x: 300
C)x: 303
D)There is no output due to compilation errors.
Question
What is the syntax error in the following if statement? <strong>What is the syntax error in the following if statement?   </strong> A)There should be an else condition B)The condition does not evaluate to a Boolean value C)The variable count should be part of the string D)It is never possible to use the / operator in an if statement <div style=padding-top: 35px>

A)There should be an "else" condition
B)The condition does not evaluate to a Boolean value
C)The variable count should be part of the string
D)It is never possible to use the "/" operator in an if statement
Question
Which of the following statements is (are) true about an if statement?
I.It guarantees that several statements are always executed in a specified order.
II.It repeats a set of statements as long as the condition is true.
III.It allows the program to carry out

A)I only
B)II only
C)III only
D)I, II, III
Question
Which of the following statements is correct about an if statement?

A)You must use braces if the body of an if statement contains only a single statement.
B)You can omit an else statement if there is no task defined in the else branch.
C)You cannot use braces if the body of an if statement contains only a single statement.
D)The number of opening braces can be
Question
Which of the following operators is used as a relational operator?

A)=<
B)<=
C)=
D)!
Question
What are the two parts of an if statement?

A)A condition and a body
B)A check and an increment
C)An increment and a body
D)An increment and a return value
Question
The operator !> stands for

A)not less than.
B)not greater than.
C)not equal to.
D)this is not an operator in Java
Question
The following code snippet contains an error.What is the error? <strong>The following code snippet contains an error.What is the error?   </strong> A)Syntax error (won't compile) B)Logical error: use of an uninitialized variable C)Logical error: if statement has do-nothing statement after if condition D)Logical error: assignment statement does not show equality <div style=padding-top: 35px>

A)Syntax error (won't compile)
B)Logical error: use of an uninitialized variable
C)Logical error: if statement has do-nothing statement after if condition
D)Logical error: assignment statement does not show equality
Question
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4 <div style=padding-top: 35px>

A)1
B)2
C)3
D)4
Question
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4 <div style=padding-top: 35px>

A)1
B)2
C)3
D)4
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)500 C)Not 500 D)500. <div style=padding-top: 35px>

A)There is no output due to compilation errors.
B)500
C)Not 500
D)500.
Question
Which of the following operators is NOT a relational operator?

A)<=
B)+=
C)!=
D)==
Question
A store applies a 15 percent service charge on all items with a price of at least $150.No service charge is otherwise applicable.Which of the following DOES NOT correctly compute the service charge?

A) double servicecharge =0;
if (cos t>=150)
{
serviceCharge =0.15 * cost;
}
B) double serviceCharge =0.15^* cost;
if (cos t<=150)
{
serviceCharge =0;
}
C) double serviceCharge;
if (cost<150)
{
serviceCharge =0;
}
else
{
serviceCharge =0.15 * cost;
}
D) double servicecharge =15;
if (cost>=150)
{
serviceCharge =0.15 * cost;
}
else
{
serviceCharge =0;
}
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)his B)hiscycle C)cycle D)There is no output due to compilation errors. <div style=padding-top: 35px>

A)his
B)hiscycle
C)cycle
D)There is no output due to compilation errors.
Question
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4 <div style=padding-top: 35px>

A)1
B)2
C)3
D)4
Question
Assuming that the user provides 49 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 49 as input, what is the output of the following code snippet?   </strong> A)x: 0 B)x: 49 C)x: 50 D)There is no output due to compilation errors. <div style=padding-top: 35px>

A)x: 0
B)x: 49
C)x: 50
D)There is no output due to compilation errors.
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)100 C)Not 100 D)100. E)Not 100. <div style=padding-top: 35px>

A)There is no output due to compilation errors.
B)100
C)Not 100
D)100.
E)Not 100.
Question
The two strings "Aardvark" and "Aardvandermeer" are exactly the same up to the first six letters.What is their correct lexicographical ordering?

A)They cannot be compared lexicographically unless they are the same length
B)"Aardvandermeer" is first, then "Aardvark"
C)"Aardvark" is first, then "Aardvandermeer"
D)The shorter word is always first
Question
Which code snippet will always output "Yes!" when s1 and s2 are two strings the contain the same sequence of characters?

A) if (s1=s2)
{
System. out. println ("Yes!");
}
B) if (s1==s2)
{
System. out.println ("Yes!");
}
C) if (s1.equals (s2))
{
System. out.println ("Yes!");
}
D) if (s1 .compareTo (s2)==1)
{
System. out. println ("Yes!");
}
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)her B)hercart C)cart D)carther <div style=padding-top: 35px>

A)her
B)hercart
C)cart
D)carther
Question
Which if statement is true when the length of string s1 is greater than 42?

A)if (s1.length() > 42)
B)if (s1.length() != 42)
C)if (42 > s1.length())
D)if (42 != s1.length())
Question
Assuming that the user provides 3 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 3 as input, what is the output of the following code snippet?   </strong> A)x: 2 B)x: 4 C)x: 6 D)There is no output due to compilation errors. <div style=padding-top: 35px>

A)x: 2
B)x: 4
C)x: 6
D)There is no output due to compilation errors.
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)49 B)50 C)51 D)52 <div style=padding-top: 35px>

A)49
B)50
C)51
D)52
Question
What is the conditional required to check whether the length of a string s1 is odd?

A)if ((s1.length() % 2) == 0)
B)if ((s1.length() % 2) != 0)
C)if ((s1.length() / 2))
D)if ((s1.length() * 2))
Question
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)One B)OneThree C)TwoThree D)OneTwoThree <div style=padding-top: 35px>

A)One
B)OneThree
C)TwoThree
D)OneTwoThree
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)You are wise! C)You have much to learn! D)You are wise! You have much to learn! <div style=padding-top: 35px>

A)There is no output due to compilation errors.
B)You are wise!
C)You have much to learn!
D)You are wise!
You have much to learn!
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)Minimum salary requirement is not met. B)Maximum salary limit is exceeded. C)Salary requirement is met. D)There is no output. <div style=padding-top: 35px>

A)Minimum salary requirement is not met.
B)Maximum salary limit is exceeded.
C)Salary requirement is met.
D)There is no output.
Question
Which condition, when supplied in the if statement below in place of (...), will correctly protect against division by zero? <strong>Which condition, when supplied in the if statement below in place of (...), will correctly protect against division by zero?   </strong> A)(grade == 0) B)((grade / num) == 0) C)(num == 0) D)(num != 0) <div style=padding-top: 35px>

A)(grade == 0)
B)((grade / num) == 0)
C)(num == 0)
D)(num != 0)
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)27 B)28 C)29 D)30 <div style=padding-top: 35px>

A)27
B)28
C)29
D)30
Question
What is the value of the price variable after the following code snippet is executed? <strong>What is the value of the price variable after the following code snippet is executed?   </strong> A)42 B)52 C)84 D)64 <div style=padding-top: 35px>

A)42
B)52
C)84
D)64
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)1 B)2 C)3 D)123 <div style=padding-top: 35px>

A)1
B)2
C)3
D)123
Question
Which of the following conditions can be added to the code below so it will assign the larger value of two integer variables a and b to the integer variable maximum? <strong>Which of the following conditions can be added to the code below so it will assign the larger value of two integer variables a and b to the integer variable maximum?   </strong> A)a == b B)b > a C)a > b D)a.compareTo (b) > 0 <div style=padding-top: 35px>

A)a == b
B)b > a
C)a > b
D)a.compareTo (b) > 0
Question
Assuming that a user enters 5 as the value for num, what is the output of the following code snippet? <strong>Assuming that a user enters 5 as the value for num, what is the output of the following code snippet?   </strong> A)0 B)9 C)5 D)11 <div style=padding-top: 35px>

A)0
B)9
C)5
D)11
Question
Which of the following conditions will correctly check if the String variable early comes before "middle" alphabetically?

A)if (greeting <= "middle")
B)if (greeting.compareTo("middle") > 0)
C)if (greeting.compareTo("middle") == 0)
D)if (early.compareTo("middle") < 0)
Question
Assuming that the user enters 60 as the input, what is the output after running the following code snippet? <strong>Assuming that the user enters 60 as the input, what is the output after running the following code snippet?   </strong> A)Too small! B)Intermediate! C)High! D)Too high! <div style=padding-top: 35px>

A)Too small!
B)Intermediate!
C)High!
D)Too high!
Question
Which of the following conditions is true exactly when the integer variable number is even?

A)number / 2 == 0
B)number > 2
C)number / 2 > 1
D)number % 2 == 0
Question
Which observation about the switch statement in Java is true?

A)The switch statement is like a sequence of if statements that compares a single value against several constant alternatives.
B)The switch statement is a compound statement that tests all branches against different variables.
C)The switch statement requires compound Boolean expressions as alternatives.
D)The switch statement is no longer valid in the most recent version of Java.
Question
Which of the following conditions is true exactly when the integer variables a, b, and c contain three different values?

A)(a != b) && (a != c) && (b != c)
B)(a != b) || (a != c) || (b != c)
C)!((a == b) && (b == c) && (a == c))
D)a != b != c
Question
Consider the following code snippet.Assuming that the user enters first 20 and then 12 as the two input values, what is the output of the code snippet? <strong>Consider the following code snippet.Assuming that the user enters first 20 and then 12 as the two input values, what is the output of the code snippet?   </strong> A)num1 = 20 num2 = 12 num3 = 20 num4 = 20 num5 = 0 B)num1 = 20 num2 = 12 num3 = 12 num4 = 0 num5 = 20 C)num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0 D)num1 = 20 num2 = 12 num3 = 20 num4 = 0 num5 = 20 <div style=padding-top: 35px>

A)num1 = 20 num2 = 12 num3 = 20 num4 = 20 num5 = 0
B)num1 = 20 num2 = 12 num3 = 12 num4 = 0 num5 = 20
C)num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0
D)num1 = 20 num2 = 12 num3 = 20 num4 = 0 num5 = 20
Question
Suppose you want to write an if statement with multiple alternatives to print out someone's tax bracket based on their income.Assume the integer variable income holds the annual income.What is wrong with the following if statement? <strong>Suppose you want to write an if statement with multiple alternatives to print out someone's tax bracket based on their income.Assume the integer variable income holds the annual income.What is wrong with the following if statement?   </strong> A)The conditions are in the wrong order; the check for the highest bracket should be first B)The conditions should use an if/ else if/else sequence, not just independent if statements C)The conditions should be a switch statement instead D)Nothing is wrong - the if statement will correctly print out the correct tax brackets <div style=padding-top: 35px>

A)The conditions are in the wrong order; the check for the highest bracket should be first
B)The conditions should use an if/ else if/else sequence, not just independent if statements
C)The conditions should be a switch statement instead
D)Nothing is wrong - the if statement will correctly print out the correct tax brackets
Question
Consider a situation where multiple if statements are combined into a chain to evaluate a complex condition.Which of the following reserved words is used to define the branch to be executed when none of the conditions are true?

A)if
B)else if
C)else
D)All of the above items
Question
Consider the following code snippet.Assuming that the user inputs 75 as the age, what is the output? <strong>Consider the following code snippet.Assuming that the user inputs 75 as the age, what is the output?   </strong> A)Impressively old B)Child Young adult Old C)Young adult Old D)Child Young adult Old Impressively old <div style=padding-top: 35px>

A)Impressively old
B)Child Young adult Old
C)Young adult Old
D)Child Young adult Old Impressively old
Question
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)0 B)1 C)2 D)7 <div style=padding-top: 35px>

A)0
B)1
C)2
D)7
Question
Which of the following conditions will correctly check if the String variable greeting is "bonjour"?

A)if (greeting == "bonjour")
B)if (greeting.compareTo("bonjour") < 0)
C)if (greeting.equals("bonjour"))
D)if (greeting.compareTo("bonjour") > 0)
Question
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4 <div style=padding-top: 35px>

A)1
B)2
C)3
D)4
Question
In a switch statement, if a break statement is missing

A)the break happens at the end of each branch by default
B)the statement will not compile
C)execution falls through the next branch until a break statement is reached
D)the default case is automatically executed
Question
Which of the following conditions is true exactly when the integer variable middle is between the values 0 and 10?

A)(0 <= middle) && (middle <= 10)
B)0 <= middle <= 10
C)(0 <= middle) || (middle <= 10)
D)(0 <= 10) && (middle <= 10)
Question
Consider the following code snippet: <strong>Consider the following code snippet:   Assuming that the user input is 40, which block of statements is executed? </strong> A)if (number > 30) { ...} B)else if (number > 20) { ...} C)else if (number > 10) { ...} D)else { ...} <div style=padding-top: 35px> Assuming that the user input is 40, which block of statements is executed?

A)if (number > 30) { ...}
B)else if (number > 20) { ...}
C)else if (number > 10) { ...}
D)else { ...}
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?  </strong> A) Petite B) Petite Small C) Small Medium D) Medium Large <div style=padding-top: 35px>

A) Petite
B) Petite
Small
C) Small
Medium
D) Medium
Large
Question
Consider the following code snippet.What is the output? <strong>Consider the following code snippet.What is the output?   </strong> A)You need to practice! B)Almost respectable!You hit triple digits! C)You hit triple digits!Impressive! D)Almost respectable!You hit triple digits!Impressive! <div style=padding-top: 35px>

A)You need to practice!
B)Almost respectable!You hit triple digits!
C)You hit triple digits!Impressive!
D)Almost respectable!You hit triple digits!Impressive!
Question
Which of the following statements is true about the "nested if" structure?

A)It cannot have any else branches at all.
B)It allows multiple else branches in a single if statement.
C)It allows one if statement within another if statement.
D)It does not allow more than one if statement nested within another if statement.
Question
Which of the following options correctly represents a "nested if" structure?

A) if (cost<70)
{
if ( tax_rate <0.10) {. . .}
}
B) If (cost<70) {. . .}
if ( tax_rate <0.10) {. . .}
C) If (cos t<70) {...}
else {. . .}
if (tax_rate <0.10) {. . .}
D) if (cost<70) {...}
{
else
{
if ( tax_rate <0.10) {. . . }
}
}
Question
What is the output of the following code snippet?
int x = 25;
if (x < 100)
{
x = x + 5;
}
if (x < 500)
{
x = x - 2;
}
if (x > 10)
{
x++;
}
else
{
x--;
}
System.out.println(x);

A)27
B)28
C)29
D)30
Question
What is the value of num after you run the following code snippet? <strong>What is the value of num after you run the following code snippet?   </strong> A)99 B)100 C)101 D)102 <div style=padding-top: 35px>

A)99
B)100
C)101
D)102
Question
What is the output after running the following code snippet? <strong>What is the output after running the following code snippet?   </strong> A)Low spender B)Spending in moderation C)Above average! D)High Roller! <div style=padding-top: 35px>

A)Low spender
B)Spending in moderation
C)Above average!
D)High Roller!
Question
What is the value of the magicPowers variable after executing the following code snippet? <strong>What is the value of the magicPowers variable after executing the following code snippet?   </strong> A)Golden sword Shining lantern Magic beans B)Shining lantern Magic beans C)Magic beans D)An empty string <div style=padding-top: 35px>

A)Golden sword Shining lantern Magic beans
B)Shining lantern Magic beans
C)Magic beans
D)An empty string
Question
If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?

<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)  <div style=padding-top: 35px>

A)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)  <div style=padding-top: 35px>
B)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)  <div style=padding-top: 35px>
C)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)  <div style=padding-top: 35px>
D)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)  <div style=padding-top: 35px>
Question
What is the value of the cost variable after the following code snippet is executed? <strong>What is the value of the cost variable after the following code snippet is executed?   </strong> A)82 B)92 C)184 D)164 <div style=padding-top: 35px>

A)82
B)92
C)184
D)164
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)Astounding! B)Professional! C)Pretty good! D)Keep your day job! <div style=padding-top: 35px>

A)Astounding!
B)Professional!
C)Pretty good!
D)Keep your day job!
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)95 B)100 C)105 D)110 <div style=padding-top: 35px>

A)95
B)100
C)105
D)110
Question
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)F B)C C)B D)FCB <div style=padding-top: 35px>

A)F
B)C
C)B
D)FCB
Question
An if statement inside another if statement is called a

A)switch statement
B)nested if statement
C)break statement
D)syntax error, since that is not permitted in Java
Question
To which of the following coding techniques can hand-tracing be applied?

A)Pseudocode
B)Java code
C)Both pseudocode and Java code
D)Neither pseudocode nor Java code
Question
Which of the following options refers to the technique of simulating program execution on a sheet of paper?

A)Compiling
B)Prototyping
C)Hand-Tracing
D)Debugging
Question
Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what is the output of the following code snippet? <strong>Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what is the output of the following code snippet?   </strong> A)0 B)10 C)20 D)30 <div style=padding-top: 35px>

A)0
B)10
C)20
D)30
Question
Assuming that a user enters 5 as the age, what is the output of the following code snippet? <strong>Assuming that a user enters 5 as the age, what is the output of the following code snippet?  </strong> A) Kid B) Kid Young C) Kid YoungAged D) Kid YoungAgedold <div style=padding-top: 35px>

A) Kid
B) Kid
Young
C) Kid
YoungAged
D) Kid
YoungAgedold
Question
When an if statement is nested inside another if statement, it creates the possibility of

A)an infinite loop
B)the misuse of the break statement
C)type mismatch
D)the dangling else
Question
A company applies a discount based on the size of the order.If the order is over $50, the discount is 5%.If the order is over $100, the discount is 10%.Otherwise, there is no discount.If the integer variable order contains the size of the order, which of the following will assign the double variable discount the correct value?

A) if (order > 100)
discount =0.10;
else if (order > 50)
discount =0.05;
else
discount =0;
B) If (order > 100)
discount =0.10;
if (order > 50)
discount =0.05;
else
discount =0;
C) if (order > 100)
discount =0.10;
if (order >50 )
discount =0.05;
if (order <=50 )
discount =0;
D) if (order > 50)
discount =0.05;
else if (order > 100)
discount =0.10;
else
discount =0;
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/119
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 5: Decisions
1
Assuming that a user enters 15 as input, what is the output of the following code snippet? <strong>Assuming that a user enters 15 as input, what is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)The number is LARGE! C)The number is SMALL! D)The number is LARGE! The number is SMALL!

A)There is no output due to compilation errors.
B)The number is LARGE!
C)The number is SMALL!
D)The number is LARGE!
The number is SMALL!
The number is SMALL!
2
Which of the following statements is true about the if statement?

A)The if statement can have only one condition that evaluates to an integer value.
B)The if block is optional.
C)The else block is optional.
D)The if and else blocks should always be included within curly braces.
The else block is optional.
3
A store provides 10 percent discount on all items with a price of at least $100.No discount is otherwise applicable.Which of the following DOES NOT correctly compute the discount?

A) double discount =0;
if ( price >=100)
{
discount =0.10^{*} price;
}
B) double discount =0.10 * price;
if ( price <=100)
{
discount =0;
}
C) double discount;
if (price <100 )
{
discount =0;
}
else
{
discount =0.10* price;
}
D) double discount =10;
if ( price >=100)
{
discount =0.1 * price;
}
else
{
discount =0;
}
double discount =0.10 * price;
if ( price <=100)
{
discount =0;
}
4
Consider the following code snippet.What is the potential problem with the if statement? <strong>Consider the following code snippet.What is the potential problem with the if statement?   </strong> A)Using == to test the double variable average for equality is error-prone. B)The conditional will not evaluate to a Boolean value. C)The assignment operator should not be used within an if-statement conditional. D)Literals should never be used in if statement conditionals.

A)Using == to test the double variable average for equality is error-prone.
B)The conditional will not evaluate to a Boolean value.
C)The assignment operator should not be used within an if-statement conditional.
D)Literals should never be used in if statement conditionals.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
5
What is the best way to improve the following code fragment? <strong>What is the best way to improve the following code fragment?   </strong> A)Move the duplicated code outside of the if statement B)Shorten variable names C)Move the brackets to save several lines of code D)Add semicolons after the if condition and the else reserved word

A)Move the duplicated code outside of the if statement
B)Shorten variable names
C)Move the brackets to save several lines of code
D)Add semicolons after the if condition and the else reserved word
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
6
What is the output of the following code snippet?

<strong>What is the output of the following code snippet?    </strong> A)Minimum income requirement is not met. B)Maximum income limit is exceeded. C)Income requirement is met. D)There is no output.

A)Minimum income requirement is not met.
B)Maximum income limit is exceeded.
C)Income requirement is met.
D)There is no output.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
7
Assuming that the user provides 99 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 99 as input, what is the output of the following code snippet?   </strong> A)a: 0 B)a: 99 C)a: 100 D)a: 300

A)a: 0
B)a: 99
C)a: 100
D)a: 300
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following is the correct syntax for an if statement?

A) if (x<10) {size = "Small"; }
else (x<20) {size = "Medium"; }
B) if (x<10) ;{ size =" Small"; }
else (x<20) {size = "Medium"; }
C) if (x<10) {size =" Sma11 " ;}
else { size = "Medium";}
D) if { size ="Small"; }
else (x<20) {size = "Medium"; }
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
9
What kind of operator is the <= operator?

A)Ternary
B)Arithmetic
C)Inequality
D)Relational
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
10
Suppose one needs an if statement to check whether an integer variable pitch is equal to 440 (which is the frequency of the note "A" to which strings and orchestras tune).Which condition is correct?

A)if (pitch - 440 = 0)
B)if ((pitch !< 440) && (pitch !> 440))
C)if (pitch = 440)
D)if (pitch == 440)
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
11
Which statement about an if statement is true?

A)The condition in an if statement using relational operators will evaluate to a Boolean result
B)The condition in an if statement should make exact comparisons to floating-point numbers
C)The condition in an if statement should always evaluate to true
D)The condition in an if statement should never include integer variables
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
12
What is the output of the following code snippet if the input is 25? <strong>What is the output of the following code snippet if the input is 25?   </strong> A)24 B)25 C)26 D)27

A)24
B)25
C)26
D)27
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
13
Assuming that the user provides 303 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 303 as input, what is the output of the following code snippet?   </strong> A)x: 0 B)x: 300 C)x: 303 D)There is no output due to compilation errors.

A)x: 0
B)x: 300
C)x: 303
D)There is no output due to compilation errors.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
14
What is the syntax error in the following if statement? <strong>What is the syntax error in the following if statement?   </strong> A)There should be an else condition B)The condition does not evaluate to a Boolean value C)The variable count should be part of the string D)It is never possible to use the / operator in an if statement

A)There should be an "else" condition
B)The condition does not evaluate to a Boolean value
C)The variable count should be part of the string
D)It is never possible to use the "/" operator in an if statement
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements is (are) true about an if statement?
I.It guarantees that several statements are always executed in a specified order.
II.It repeats a set of statements as long as the condition is true.
III.It allows the program to carry out

A)I only
B)II only
C)III only
D)I, II, III
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements is correct about an if statement?

A)You must use braces if the body of an if statement contains only a single statement.
B)You can omit an else statement if there is no task defined in the else branch.
C)You cannot use braces if the body of an if statement contains only a single statement.
D)The number of opening braces can be
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following operators is used as a relational operator?

A)=<
B)<=
C)=
D)!
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
18
What are the two parts of an if statement?

A)A condition and a body
B)A check and an increment
C)An increment and a body
D)An increment and a return value
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
19
The operator !> stands for

A)not less than.
B)not greater than.
C)not equal to.
D)this is not an operator in Java
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
20
The following code snippet contains an error.What is the error? <strong>The following code snippet contains an error.What is the error?   </strong> A)Syntax error (won't compile) B)Logical error: use of an uninitialized variable C)Logical error: if statement has do-nothing statement after if condition D)Logical error: assignment statement does not show equality

A)Syntax error (won't compile)
B)Logical error: use of an uninitialized variable
C)Logical error: if statement has do-nothing statement after if condition
D)Logical error: assignment statement does not show equality
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
21
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4

A)1
B)2
C)3
D)4
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
22
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4

A)1
B)2
C)3
D)4
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
23
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)500 C)Not 500 D)500.

A)There is no output due to compilation errors.
B)500
C)Not 500
D)500.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following operators is NOT a relational operator?

A)<=
B)+=
C)!=
D)==
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
25
A store applies a 15 percent service charge on all items with a price of at least $150.No service charge is otherwise applicable.Which of the following DOES NOT correctly compute the service charge?

A) double servicecharge =0;
if (cos t>=150)
{
serviceCharge =0.15 * cost;
}
B) double serviceCharge =0.15^* cost;
if (cos t<=150)
{
serviceCharge =0;
}
C) double serviceCharge;
if (cost<150)
{
serviceCharge =0;
}
else
{
serviceCharge =0.15 * cost;
}
D) double servicecharge =15;
if (cost>=150)
{
serviceCharge =0.15 * cost;
}
else
{
serviceCharge =0;
}
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
26
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)his B)hiscycle C)cycle D)There is no output due to compilation errors.

A)his
B)hiscycle
C)cycle
D)There is no output due to compilation errors.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
27
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4

A)1
B)2
C)3
D)4
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
28
Assuming that the user provides 49 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 49 as input, what is the output of the following code snippet?   </strong> A)x: 0 B)x: 49 C)x: 50 D)There is no output due to compilation errors.

A)x: 0
B)x: 49
C)x: 50
D)There is no output due to compilation errors.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
29
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)100 C)Not 100 D)100. E)Not 100.

A)There is no output due to compilation errors.
B)100
C)Not 100
D)100.
E)Not 100.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
30
The two strings "Aardvark" and "Aardvandermeer" are exactly the same up to the first six letters.What is their correct lexicographical ordering?

A)They cannot be compared lexicographically unless they are the same length
B)"Aardvandermeer" is first, then "Aardvark"
C)"Aardvark" is first, then "Aardvandermeer"
D)The shorter word is always first
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
31
Which code snippet will always output "Yes!" when s1 and s2 are two strings the contain the same sequence of characters?

A) if (s1=s2)
{
System. out. println ("Yes!");
}
B) if (s1==s2)
{
System. out.println ("Yes!");
}
C) if (s1.equals (s2))
{
System. out.println ("Yes!");
}
D) if (s1 .compareTo (s2)==1)
{
System. out. println ("Yes!");
}
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
32
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)her B)hercart C)cart D)carther

A)her
B)hercart
C)cart
D)carther
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
33
Which if statement is true when the length of string s1 is greater than 42?

A)if (s1.length() > 42)
B)if (s1.length() != 42)
C)if (42 > s1.length())
D)if (42 != s1.length())
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
34
Assuming that the user provides 3 as input, what is the output of the following code snippet? <strong>Assuming that the user provides 3 as input, what is the output of the following code snippet?   </strong> A)x: 2 B)x: 4 C)x: 6 D)There is no output due to compilation errors.

A)x: 2
B)x: 4
C)x: 6
D)There is no output due to compilation errors.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
35
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)49 B)50 C)51 D)52

A)49
B)50
C)51
D)52
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
36
What is the conditional required to check whether the length of a string s1 is odd?

A)if ((s1.length() % 2) == 0)
B)if ((s1.length() % 2) != 0)
C)if ((s1.length() / 2))
D)if ((s1.length() * 2))
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
37
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)One B)OneThree C)TwoThree D)OneTwoThree

A)One
B)OneThree
C)TwoThree
D)OneTwoThree
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
38
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)There is no output due to compilation errors. B)You are wise! C)You have much to learn! D)You are wise! You have much to learn!

A)There is no output due to compilation errors.
B)You are wise!
C)You have much to learn!
D)You are wise!
You have much to learn!
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
39
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)Minimum salary requirement is not met. B)Maximum salary limit is exceeded. C)Salary requirement is met. D)There is no output.

A)Minimum salary requirement is not met.
B)Maximum salary limit is exceeded.
C)Salary requirement is met.
D)There is no output.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
40
Which condition, when supplied in the if statement below in place of (...), will correctly protect against division by zero? <strong>Which condition, when supplied in the if statement below in place of (...), will correctly protect against division by zero?   </strong> A)(grade == 0) B)((grade / num) == 0) C)(num == 0) D)(num != 0)

A)(grade == 0)
B)((grade / num) == 0)
C)(num == 0)
D)(num != 0)
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
41
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)27 B)28 C)29 D)30

A)27
B)28
C)29
D)30
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
42
What is the value of the price variable after the following code snippet is executed? <strong>What is the value of the price variable after the following code snippet is executed?   </strong> A)42 B)52 C)84 D)64

A)42
B)52
C)84
D)64
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
43
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)1 B)2 C)3 D)123

A)1
B)2
C)3
D)123
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following conditions can be added to the code below so it will assign the larger value of two integer variables a and b to the integer variable maximum? <strong>Which of the following conditions can be added to the code below so it will assign the larger value of two integer variables a and b to the integer variable maximum?   </strong> A)a == b B)b > a C)a > b D)a.compareTo (b) > 0

A)a == b
B)b > a
C)a > b
D)a.compareTo (b) > 0
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
45
Assuming that a user enters 5 as the value for num, what is the output of the following code snippet? <strong>Assuming that a user enters 5 as the value for num, what is the output of the following code snippet?   </strong> A)0 B)9 C)5 D)11

A)0
B)9
C)5
D)11
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following conditions will correctly check if the String variable early comes before "middle" alphabetically?

A)if (greeting <= "middle")
B)if (greeting.compareTo("middle") > 0)
C)if (greeting.compareTo("middle") == 0)
D)if (early.compareTo("middle") < 0)
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
47
Assuming that the user enters 60 as the input, what is the output after running the following code snippet? <strong>Assuming that the user enters 60 as the input, what is the output after running the following code snippet?   </strong> A)Too small! B)Intermediate! C)High! D)Too high!

A)Too small!
B)Intermediate!
C)High!
D)Too high!
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following conditions is true exactly when the integer variable number is even?

A)number / 2 == 0
B)number > 2
C)number / 2 > 1
D)number % 2 == 0
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
49
Which observation about the switch statement in Java is true?

A)The switch statement is like a sequence of if statements that compares a single value against several constant alternatives.
B)The switch statement is a compound statement that tests all branches against different variables.
C)The switch statement requires compound Boolean expressions as alternatives.
D)The switch statement is no longer valid in the most recent version of Java.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
50
Which of the following conditions is true exactly when the integer variables a, b, and c contain three different values?

A)(a != b) && (a != c) && (b != c)
B)(a != b) || (a != c) || (b != c)
C)!((a == b) && (b == c) && (a == c))
D)a != b != c
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
51
Consider the following code snippet.Assuming that the user enters first 20 and then 12 as the two input values, what is the output of the code snippet? <strong>Consider the following code snippet.Assuming that the user enters first 20 and then 12 as the two input values, what is the output of the code snippet?   </strong> A)num1 = 20 num2 = 12 num3 = 20 num4 = 20 num5 = 0 B)num1 = 20 num2 = 12 num3 = 12 num4 = 0 num5 = 20 C)num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0 D)num1 = 20 num2 = 12 num3 = 20 num4 = 0 num5 = 20

A)num1 = 20 num2 = 12 num3 = 20 num4 = 20 num5 = 0
B)num1 = 20 num2 = 12 num3 = 12 num4 = 0 num5 = 20
C)num1 = 20 num2 = 12 num3 = 12 num4 = 20 num5 = 0
D)num1 = 20 num2 = 12 num3 = 20 num4 = 0 num5 = 20
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
52
Suppose you want to write an if statement with multiple alternatives to print out someone's tax bracket based on their income.Assume the integer variable income holds the annual income.What is wrong with the following if statement? <strong>Suppose you want to write an if statement with multiple alternatives to print out someone's tax bracket based on their income.Assume the integer variable income holds the annual income.What is wrong with the following if statement?   </strong> A)The conditions are in the wrong order; the check for the highest bracket should be first B)The conditions should use an if/ else if/else sequence, not just independent if statements C)The conditions should be a switch statement instead D)Nothing is wrong - the if statement will correctly print out the correct tax brackets

A)The conditions are in the wrong order; the check for the highest bracket should be first
B)The conditions should use an if/ else if/else sequence, not just independent if statements
C)The conditions should be a switch statement instead
D)Nothing is wrong - the if statement will correctly print out the correct tax brackets
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
53
Consider a situation where multiple if statements are combined into a chain to evaluate a complex condition.Which of the following reserved words is used to define the branch to be executed when none of the conditions are true?

A)if
B)else if
C)else
D)All of the above items
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
54
Consider the following code snippet.Assuming that the user inputs 75 as the age, what is the output? <strong>Consider the following code snippet.Assuming that the user inputs 75 as the age, what is the output?   </strong> A)Impressively old B)Child Young adult Old C)Young adult Old D)Child Young adult Old Impressively old

A)Impressively old
B)Child Young adult Old
C)Young adult Old
D)Child Young adult Old Impressively old
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
55
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)0 B)1 C)2 D)7

A)0
B)1
C)2
D)7
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
56
Which of the following conditions will correctly check if the String variable greeting is "bonjour"?

A)if (greeting == "bonjour")
B)if (greeting.compareTo("bonjour") < 0)
C)if (greeting.equals("bonjour"))
D)if (greeting.compareTo("bonjour") > 0)
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
57
What is the output of the statements below? <strong>What is the output of the statements below?   </strong> A)1 B)2 C)3 D)4

A)1
B)2
C)3
D)4
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
58
In a switch statement, if a break statement is missing

A)the break happens at the end of each branch by default
B)the statement will not compile
C)execution falls through the next branch until a break statement is reached
D)the default case is automatically executed
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
59
Which of the following conditions is true exactly when the integer variable middle is between the values 0 and 10?

A)(0 <= middle) && (middle <= 10)
B)0 <= middle <= 10
C)(0 <= middle) || (middle <= 10)
D)(0 <= 10) && (middle <= 10)
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
60
Consider the following code snippet: <strong>Consider the following code snippet:   Assuming that the user input is 40, which block of statements is executed? </strong> A)if (number > 30) { ...} B)else if (number > 20) { ...} C)else if (number > 10) { ...} D)else { ...} Assuming that the user input is 40, which block of statements is executed?

A)if (number > 30) { ...}
B)else if (number > 20) { ...}
C)else if (number > 10) { ...}
D)else { ...}
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
61
What is the output of the following code snippet? <strong>What is the output of the following code snippet?  </strong> A) Petite B) Petite Small C) Small Medium D) Medium Large

A) Petite
B) Petite
Small
C) Small
Medium
D) Medium
Large
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
62
Consider the following code snippet.What is the output? <strong>Consider the following code snippet.What is the output?   </strong> A)You need to practice! B)Almost respectable!You hit triple digits! C)You hit triple digits!Impressive! D)Almost respectable!You hit triple digits!Impressive!

A)You need to practice!
B)Almost respectable!You hit triple digits!
C)You hit triple digits!Impressive!
D)Almost respectable!You hit triple digits!Impressive!
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
63
Which of the following statements is true about the "nested if" structure?

A)It cannot have any else branches at all.
B)It allows multiple else branches in a single if statement.
C)It allows one if statement within another if statement.
D)It does not allow more than one if statement nested within another if statement.
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
64
Which of the following options correctly represents a "nested if" structure?

A) if (cost<70)
{
if ( tax_rate <0.10) {. . .}
}
B) If (cost<70) {. . .}
if ( tax_rate <0.10) {. . .}
C) If (cos t<70) {...}
else {. . .}
if (tax_rate <0.10) {. . .}
D) if (cost<70) {...}
{
else
{
if ( tax_rate <0.10) {. . . }
}
}
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
65
What is the output of the following code snippet?
int x = 25;
if (x < 100)
{
x = x + 5;
}
if (x < 500)
{
x = x - 2;
}
if (x > 10)
{
x++;
}
else
{
x--;
}
System.out.println(x);

A)27
B)28
C)29
D)30
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
66
What is the value of num after you run the following code snippet? <strong>What is the value of num after you run the following code snippet?   </strong> A)99 B)100 C)101 D)102

A)99
B)100
C)101
D)102
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
67
What is the output after running the following code snippet? <strong>What is the output after running the following code snippet?   </strong> A)Low spender B)Spending in moderation C)Above average! D)High Roller!

A)Low spender
B)Spending in moderation
C)Above average!
D)High Roller!
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
68
What is the value of the magicPowers variable after executing the following code snippet? <strong>What is the value of the magicPowers variable after executing the following code snippet?   </strong> A)Golden sword Shining lantern Magic beans B)Shining lantern Magic beans C)Magic beans D)An empty string

A)Golden sword Shining lantern Magic beans
B)Shining lantern Magic beans
C)Magic beans
D)An empty string
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
69
If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?

<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)

A)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)
B)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)
C)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)
D)<strong>If the user enters 22 as the price of an object, which of the following hand-trace tables is valid for this code snippet?    </strong> A)  B)  C)  D)
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
70
What is the value of the cost variable after the following code snippet is executed? <strong>What is the value of the cost variable after the following code snippet is executed?   </strong> A)82 B)92 C)184 D)164

A)82
B)92
C)184
D)164
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
71
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)Astounding! B)Professional! C)Pretty good! D)Keep your day job!

A)Astounding!
B)Professional!
C)Pretty good!
D)Keep your day job!
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
72
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)95 B)100 C)105 D)110

A)95
B)100
C)105
D)110
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
73
What is the output of the following code snippet? <strong>What is the output of the following code snippet?   </strong> A)F B)C C)B D)FCB

A)F
B)C
C)B
D)FCB
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
74
An if statement inside another if statement is called a

A)switch statement
B)nested if statement
C)break statement
D)syntax error, since that is not permitted in Java
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
75
To which of the following coding techniques can hand-tracing be applied?

A)Pseudocode
B)Java code
C)Both pseudocode and Java code
D)Neither pseudocode nor Java code
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
76
Which of the following options refers to the technique of simulating program execution on a sheet of paper?

A)Compiling
B)Prototyping
C)Hand-Tracing
D)Debugging
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
77
Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what is the output of the following code snippet? <strong>Assuming that a user enters 10, 20, and 30 as input values one after another, separated by spaces, what is the output of the following code snippet?   </strong> A)0 B)10 C)20 D)30

A)0
B)10
C)20
D)30
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
78
Assuming that a user enters 5 as the age, what is the output of the following code snippet? <strong>Assuming that a user enters 5 as the age, what is the output of the following code snippet?  </strong> A) Kid B) Kid Young C) Kid YoungAged D) Kid YoungAgedold

A) Kid
B) Kid
Young
C) Kid
YoungAged
D) Kid
YoungAgedold
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
79
When an if statement is nested inside another if statement, it creates the possibility of

A)an infinite loop
B)the misuse of the break statement
C)type mismatch
D)the dangling else
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
80
A company applies a discount based on the size of the order.If the order is over $50, the discount is 5%.If the order is over $100, the discount is 10%.Otherwise, there is no discount.If the integer variable order contains the size of the order, which of the following will assign the double variable discount the correct value?

A) if (order > 100)
discount =0.10;
else if (order > 50)
discount =0.05;
else
discount =0;
B) If (order > 100)
discount =0.10;
if (order > 50)
discount =0.05;
else
discount =0;
C) if (order > 100)
discount =0.10;
if (order >50 )
discount =0.05;
if (order <=50 )
discount =0;
D) if (order > 50)
discount =0.05;
else if (order > 100)
discount =0.10;
else
discount =0;
Unlock Deck
Unlock for access to all 119 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 119 flashcards in this deck.