Deck 3: Decisionseasy

Full screen (f)
exit full mode
Question
Which of the following operators is used as a relational operator?

A) =<
B) <=
C) =
D) !
Use Space or
up arrow
down arrow
to flip the card.
Question
What is the output of the following code snippet?
Double income = 45000;
Double cutoff = 55000;
Double minIncome = 30000;
If (minIncome > income)
{
System.out.println("Minimum income requirement is not met.");
}
If (cutoff < income)
{
System.out.println("Maximum income limit is exceeded.");
}
Else
{
System.out.println("Income requirement is met.");
}

A) Minimum income requirement is not met.
B) Maximum income limit is exceeded.
C) Income requirement is met.
D) There is no output.
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 different actions depending on the value of a condition.

A) I
B) II
C) III
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 different from the number of closing braces.
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 = "Small"; }
Else { size = "Medium"; }
D) if { size = "Small"; }
Else (x < 20) { size = "Medium"; }
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
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
Assuming that a user enters 15 as input, what is the output of the following code snippet?
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
Int number = in.nextInt();
If (number > 20)
{
System.out.println("The number is LARGE!");
}
Else
{
System.out.println("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!
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
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
Assuming that the user provides 303 as input, what is the output of the following code snippet?
Int x;
Int y;
X = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
Y = in.nextInt();
If (y > 300)
{
X = y;
}
Else
{
X = 0;
}
System.out.println("x: " + x);

A) x: 0
B) x: 300
C) x: 303
D) There is no output due to compilation errors.
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
What kind of operator is the <= operator?

A) Ternary
B) Arithmetic
C) Inequality
D) Relational
Question
Assuming that a user enters 25 as the value for x, what is the output of the following code snippet?
Int x = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
X = in.nextInt();
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 output of the following code snippet if the input is 25?
Int i = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
I = in.nextInt();
If (i > 25)
{
I++;
}
Else
{
I--;
}
System.out.print(i);

A) 24
B) 25
C) 26
D) 27
Question
In Java, which of the following orderings is used to compare strings?

A) Lexicographic
B) Semantic
C) Alphabetic
D) Syntactic
Question
The following code snippet contains an error. What is the error?
If (cost > 100);
{
Cost = cost - 10;
}
System.out.println("Discount cost: " + cost);

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 can be done to improve the following code fragment?
If ((counter % 10) == 0)
{
System.out.println("Counter is divisible by ten: " + counter);
Counter++;
}
Else
{
System.out.println("Counter is not divisible by ten: "
+ counter);
Counter++;
}

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
Assuming that the user provides 99 as input, what is the output of the following code snippet?
Int a;
Int b;
A = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
B = in.nextInt();
If (b > 300)
{
A = b;
}
Else
{
A = 0;
}
System.out.println("a: " +
A) a: 0

A);
B) a: 99
C) a: 100
D) a: 300
Question
Consider the following code snippet. Assuming that the user inputs 75 as the age, what is the output?
Int age = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your age: ");
Age = in.nextInt();
If (age < 10)
{
System.out.print("Child ");
}
If (age < 30)
{
System.out.print("Young adult ");
}
If (age < 70)
{
System.out.print("Old ");
}
If (age < 100)
{
System.out.print("Impressively old ");
}

A) Impressively old
B) Child Young adult Old
C) Young adult Old
D) Child Young adult Old Impressively old
Question
What is the value of the price variable after the following code snippet is executed?
Int price = 42;
If (price < 40)
{
Price = price + 10;
}
If (price > 30)
{
Price = price * 2;
}
If (price < 100)
{
Price = price - 20;
}

A) 42
B) 52
C) 84
D) 64
Question
Consider the following code snippet. What is the potential problem with the if statement?
Double average;
Average = (g1 + g2 + g3 + g4) / 4.0;
If (average == 90.0)
{
System.out.println("You earned an A in the class!");
}

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
Assuming that a user enters 5 as the value for num, what is the output of the following code snippet?
Int num = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num = in.nextInt();
If (num < 50)
{
Num = num + 5;
}
If (num < 10)
{
Num = num - 2;
}
If (num > 5)
{
Num++;
}
Else
{
Num--;
}
System.out.println(num);

A) 0
B) 9
C) 5
D) 11
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
What is the output of the following code snippet?
String str1 = "her";
String str2 = "cart";
If (str1.compareTo(str2) < 0)
{
System.out.print(str2);
}
Else
{
System.out.print(str1);
}

A) her
B) hercart
C) cart
D) carther
Question
Which of the following options is a legally correct expression for inverting a condition?

A) if (!(a == 10))
B) if (!a == 10)
C) if (a !== 10)
D) if (a ! 10)
Question
Write an if-statement condition that is true if 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
What is the problem with the following if statement?
Double count = 15.0;
If (count / 3.0)
{
System.out.println("The value of count is ");
}

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 condition, when supplied in the if statement below in place of (. . .), will correctly protect against division by zero?
If (. . .)
{
Result = grade / num;
System.out.println("Just avoided division by zero!");
}

A) (grade == 0)
B) ((grade / num) == 0)
C) (num == 0)
D) (num != 0)
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?
Int num1 = 0;
Int num2 = 0;
Int num3 = 0;
Int num4 = 0;
Int num5 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num1 = in.nextInt();
System.out.print("Enter a number: ");
Num2 = in.nextInt();
If (num1 < num2)
{
Num3 = num1;
}
Else
{
Num3 = num2;
}
If (num1 < num2 + 10)
{
Num4 = num1;
}
Else if (num1 < num2 + 20)
{
Num5 = num1;
}
System.out.println("num1 = " + num1 + " num2 = " + num2
+ " num3 = " + num3 + " num4 = " + num4
+ " num5 = " + num5);

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
What is the output of the following code snippet?
Int num = 100;
If (num != 100)
{
System.out.println("100");
}
Else
{
System.out.println("Not 100");
}

A) There is no output due to compilation errors.
B) 100
C) Not 100
D) 100 Not 100
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
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
Assuming that the user enters 60 as the input, what is the output after running the following code snippet?
Int num = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num = in.nextInt();
If (num < 10)
{
System.out.println("Too small!");
}
Else if (num < 50)
{
System.out.println("Intermediate!");
}
Else if (num < 100)
{
System.out.println("High!");
}
Else
{
System.out.println("Too high!");
}

A) Too small!
B) Intermediate!
C) High!
D) Too high!
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
What is the output of the following code snippet?
Int s1 = 20;
If (s1 <= 20)
{
System.out.print("1");
}
If (s1 <= 40)
{
System.out.print("2");
}
If (s1 <= 20)
{
System.out.print("3");
}

A) 1
B) 2
C) 3
D) 123
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
Suppose you want to write an if statement with multiple alternatives to print out the single tax bracket that someone is in, based on their income. Assume the integer variable income holds the annual income. What is wrong with the following if statement?
If (income < 10000)
{
System.out.println("Lowest tax bracket");
}
If (income < 20000)
{
System.out.println("Low-Middle tax bracket");
}
If (income < 30000)
{
System.out.println("Middle tax bracket");
}
System.out.println("High tax bracket");

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 tax brackets
Question
Consider the following code snippet:
Int number = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Number = in.nextInt();
If (number > 30) { . . . }
Else if (number > 20) { . . .. }
Else if (number > 10) { . . . }
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 { . . . }
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 multiple else branches inside a nested if statement.
Question
When testing code for correctness, it always makes sense to

A) Test all cases
B) Identify boundary cases and test them
C) Check all cases by hand
D) Assume invalid input will never occur
Question
Which of the following operators is used to invert a conditional statement?

A) !
B) !=
C) ||
D) ?
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 (cost < 70) { . . . }
Else { . . . }
If (tax_rate < 0.10) { . . . }
D) if (cost < 70) { . . . }
{
Else
{
If (tax_rate < 0.10) { . . . }
}
}
Question
When drawing flowcharts, unconstrained branching and merging can lead to

A) So-called "spaghetti code"
B) A better design
C) Intuitive understanding of the flow of control
D) Clear visualization of the problem solution
Question
Which of the following variables is used to store a condition that can be either true or false?

A) Algebraic
B) Logical
C) Boolean
D) Conditional
Question
Which of the following expressions represents a legal way of checking whether a value assigned to the num variable falls in the range 100 to 200?

A) if (num >= 200 && num <= 100)
B) if (num >= 100 && num <= 200)
C) if (num >= 100 || num <= 200)
D) if (num >= 200 || num <= 100)
Question
Which of the following expressions represents a legal way of checking whether a value for the num variable is either less than 100 or more than 200?

A) if (num <= 100 && num >= 200)
B) if (num < 100 && num > 200)
C) if (num < 100 || num > 200)
D) if (num <= 100 || num >= 200)
Question
Which of the following operators is NOT a relational operator?

A) <=
B) +=
C) !=
D) ==
Question
What is the value of the magicPowers variable after executing the following code snippet?
String magicPowers = "";
Int experienceLevel = 9;
If (experienceLevel > 10)
{
MagicPowers = magicPowers + "Golden sword ";
}
If (experienceLevel > 8)
{
MagicPowers = magicPowers + "Shining lantern ";
}
If (experienceLevel > 2)
{
MagicPowers = magicPowers + "Magic beans ";
}

A) Golden sword Shining lantern Magic beans
B) Shining lantern Magic beans
C) Magic beans
D) An empty string
Question
Assuming that a user enters 5 as the age, what is the output of the following code snippet?
Int age = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your age: ");
Age = in.nextInt();
If (age < 10)
{
System.out.println("Kid");
}
If (age < 30)
{
System.out.print("Young");
}
If (age < 70)
{
System.out.print("Aged");
}
If (age < 100)
{
System.out.print("Old");
}

A) Kid
B) Kid
Young
C) Kid
YoungAged
D) Kid
YoungAgedOld
Question
What is the value of num after you run the following code snippet?
Int num = 100;
If (num <= 100)
{
Num++;
}
If (num <= 200)
{
Num--;
}
If (num <= 300)
{
Num++;
}
If (num <= 400)
{
Num--;
}
If (num <= 500)
{
Num++;
}

A) 99
B) 100
C) 101
D) 102
Question
Assuming that a user enters 56 for age, what is the output of the following code snippet?
Int age = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your age: ");
Age = in.nextInt();
If (age < 13)
{
System.out.println("Kid!");
}
If (age >= 13 && age < 19)
{
System.out.println("Teen!");
}
If (age >= 19 && age < 30)
{
System.out.println("Young!");
}
If (age >= 30 && age < 50)
{
System.out.println("Adult!");
}
If (age >= 50)
{
System.out.println("Old!");
}

A) Teen!
B) Young!
C) Adult!
D) Old!
Question
What is the output of the following code snippet?
Boolean attendance = false;
String str = "Unknown";
Attendance = !(attendance);
If (!attendance)
{
Str = "False";
}
If (attendance)
{
Attendance = false;
}
If (attendance)
{
Str = "True";
}
Else
{
Str = "Maybe";
}
System.out.println(str);

A) False
B) True
C) Unknown
D) Maybe
Question
What is the output of the following code snippet?
Final int MIN_SPEED = 45;
Final int MAX_SPEED = 65;
Int speed = 55;
If (!(speed < MAX_SPEED))
{
Speed = speed - 10;
}
If (!(speed > MIN_SPEED))
{
Speed = speed + 10;
}
System.out.println(speed);

A) 45
B) 55
C) 65
D) 50
Question
What is the output of the following code snippet?
Int num = 100;
If (num > 100);
{
Num = num - 10;
}
System.out.println(num);

A) 90
B) 100
C) 99
D) 101
Question
The flow chart shows the order in which steps should be executed, and the diamond-shaped boxes indicate

A) input
B) algorithms
C) tasks
D) conditional tests
Question
Assuming that a user enters 64 as his score, what is the output of the following code snippet?
Int score = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter your score: ");
Score = in.nextInt();
If (score < 40)
{
System.out.println("F");
}
Else if (score >= 40 || score < 50)
{
System.out.println("D");
}
Else if (score >= 50 || score < 60)
{
System.out.println("C");
}
Else if (score >= 60 || score < 70)
{
System.out.println("B");
}
Else if (score >= 70 || score < 80)
{
System.out.println("B+");
}
Else
{
System.out.println("A");
}

A) D
B) C
C) B
D) A
Question
Which of the following operators is used to combine two Boolean conditions?

A) ##
B) $$
C) %%
D) &&
Question
Consider the following code snippet:
Boolean attendance = true;
Boolean failed = false;
Which of the following if statement s includes a condition that evaluates to true?

A) if (attendance == "true") { . . . }
B) if (attendance) { . . . }
C) if (failed) { . . . }
D) if (attendance == failed) { . . . }
Question
What is the output of the following code snippet?
String someString1 = "his";
String someString2 = "cycle";
If (someString1.compareTo(someString2) < 0)
{
System.out.println(someString2);
}
Else
{
System.out.println(someString1);
}

A) his
B) hiscycle
C) cycle
D) There is no output due to compilation errors.
Question
Consider the following code snippet:
Int score = 0;
Double price = 100;
If (score > 0 && price < 200 && price / score > 10)
{
System.out.println("buy");
}
Which of the following statements is true on the basis of this code snippet?

A) The output is buy.
B) The code snippet compiles and runs, but there is no output.
C) The code snippet doesn't compile.
D) The code snippet causes a divide-by-zero error.
Question
What is the output of the following code snippet?
Int age = 25;
If (age > 30)
{
System.out.println("You are wise!");
}
Else
{
System.out.println("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!
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 (cost >= 150)
{
ServiceCharge = 0.15 * cost;
}
B) double serviceCharge = 0.15 * cost;
If (cost <= 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
Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet?
Int price = 0;
String status = "";
Scanner in = new Scanner(System.in);
System.out.print("Please enter object's price: ");
Price = in.nextInt();
If (price >= 50)
{
Status = "reasonable";
If (price >= 75)
{
Status = "costly";
}
}
Else
{
Status = "inexpensive";
If (price <= 25)
{
Status = "reasonable";
}
}

A) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)   <div style=padding-top: 35px>
B) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)   <div style=padding-top: 35px>
C) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)   <div style=padding-top: 35px>
D) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)   <div style=padding-top: 35px>
Question
Which of the following coding techniques can hand-tracing be applied to?

A) Pseudocode
B) Java code
C) Both pseudocode and Java code
D) Neither pseudocode nor Java code
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?
Int num1 = 0;
Int num2 = 0;
Int num3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num1 = in.nextInt();
System.out.print("Enter a number: ");
Num2 = in.nextInt();
System.out.print("Enter a number: ");
Num3 = in.nextInt();
If (num1 > num2)
{
If (num1 > num3)
{
System.out.println(num1);
}
Else
{
System.out.println(num3);
}
}
Else
{
If (num2 > num3)
{
System.out.println(num2);
}
Else
{
System.out.println(num3);
}
}

A) 0
B) 10
C) 20
D) 30
Question
Which of the following conditions tests whether the user enters an integer value that will then be assigned to the floor variable?
Int floor = 0;
Scanner in = new Scanner(System.in);
System.out.print("Floor: ");
( ) . . )
Floor = in.nextInt();

A) if (in.nextInt(floor))
B) if (in.hasNextInt())
C) if (in.fail)
D) if (in.nextInt())
Question
What is the output of the following code snippet?
Int num = 100;
If (num < 100)
{
If (num < 50)
{
Num = num - 5;
}
Else
{
Num = num - 10;
}
}
Else
{
If (num > 150)
{
Num = num + 5;
}
Else
{
Num = num + 10;
}
}
System.out.println(num);

A) 95
B) 100
C) 105
D) 110
Question
Which of the following operators compare using short-circuit evaluation?

A) ++
B) -
C) &&
D) ==
Question
Assuming that a valid price should be between 30 and 50, does the following code snippet test this condition correctly?
Final int MIN_PRICE = 30;
Final int MAX_PRICE = 50;
Int price = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter the price: ");
Price = in.nextInt();
If (price < MIN_PRICE)
{
System.out.println("Error: The price is too low.");
}
Else if (price > MAX_PRICE)
{
System.out.println("Error: The price is too high.");
}
Else
{
System.out.println("The price entered is in the valid price range.");
}

A) This code snippet ensures that the price value is between 30 and 50.
B) This code snippet only ensures that the price value is greater than 30.
C) This code snippet only ensures that the price value is less than 50.
D) This code snippet ensures that the price value is either less than 30 or greater than 50.
Question
Assuming that a user enters 45, 78, and then 12, what is the output of the following code snippet?
Int num1 = 0;
Int num2 = 0;
Int num3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num1 = in.nextInt();
System.out.print("Enter a number: ");
Num2 = in.nextInt();
System.out.print("Enter a number: ");
Num3 = in.nextInt();
If (!(num1 > num2 && num1 > num3))
{
System.out.println(num1);
}
Else if (!(num2 > num1 && num2 > num3))
{
System.out.println(num2);
}
Else if (!(num3 > num1 && num3 > num2))
{
System.out.println(num3);
}

A) 12
B) 45
C) 78
D) There is no output due to compilation errors.
Question
What is the output of the following code snippet?
Int x = 50;
If (x > 100)
{
X++;
}
Else
{
X--;
}
System.out.println(x);

A) 49
B) 50
C) 51
D) 52
Question
What is the output of the following code snippet?
Int digit = 500;
If (digit != 500)
{
System.out.println("500");
}
Else
{
System.out.println("Not 500");
}

A) There is no output due to compilation errors.
B) 500
C) Not 500
D) 500
Not 500
Question
Which of the following options checks that city is neither Chicago nor Dallas?

A) if (city != "Chicago" || city != "Dallas")
B) if !(city == "Chicago" || city == "Dallas")
C) if !(city == "Chicago" && city == "Dallas")
D) if (city != "Chicago" || city == "Dallas")
Question
Assuming that the user provides 49 as input, what is the output of the following code snippet?
Int x = 0;
Int y = 0;
System.out.print("Please enter y: ");
Scanner in = new Scanner(System.in);
Y = in.nextInt();
If (y > 50);
{
X = y;
}
System.out.println("x: " + x);

A) x: 0
B) x: 49
C) x: 50
D) There is no output due to compilation errors.
Question
Which of the following options refers to the technique of simulating program execution on a sheet of paper?

A) Compiling
B) Prototyping
C) Tracing
D) Debugging
Question
Which of the following statements can be used to validate that the user input for the floor variable is between 0 and 20 inclusive?

A) if (floor >= 0 && floor <= 20)
B) if (floor >= 0 || floor <= 20)
C) if (floor <= 0 && floor >= 20)
D) if (floor <= 0 || floor >= 20)
Question
Assuming that the user provides 3 as input, what is the output of the following code snippet?
Int x;
Int y;
X = 0;
System.out.print("Please enter y: ");
Scanner in = new Scanner(System.in);
Y = in.nextInt();
If (y > 0)
{
X = 2 * y;
}
Else
{
X = 2 + x;
}
System.out.println("x: " + x);

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?
Double salary = 55000;
Double cutOff = 65000;
Double minSalary = 40000;
If (minSalary > salary)
{
System.out.println("Minimum salary requirement is not met.");
}
If (cutOff < salary)
{
System.out.println("Maximum salary limit is exceeded.");
}
Else
{
System.out.println("Salary requirement is met.");
}

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
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/99
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Decisionseasy
1
Which of the following operators is used as a relational operator?

A) =<
B) <=
C) =
D) !
B
2
What is the output of the following code snippet?
Double income = 45000;
Double cutoff = 55000;
Double minIncome = 30000;
If (minIncome > income)
{
System.out.println("Minimum income requirement is not met.");
}
If (cutoff < income)
{
System.out.println("Maximum income limit is exceeded.");
}
Else
{
System.out.println("Income requirement is met.");
}

A) Minimum income requirement is not met.
B) Maximum income limit is exceeded.
C) Income requirement is met.
D) There is no output.
C
3
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 different actions depending on the value of a condition.

A) I
B) II
C) III
D) I, II, III
C
4
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 different from the number of closing braces.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
5
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 = "Small"; }
Else { size = "Medium"; }
D) if { size = "Small"; }
Else (x < 20) { size = "Medium"; }
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
6
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 99 flashcards in this deck.
Unlock Deck
k this deck
7
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 99 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
9
Assuming that a user enters 15 as input, what is the output of the following code snippet?
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
Int number = in.nextInt();
If (number > 20)
{
System.out.println("The number is LARGE!");
}
Else
{
System.out.println("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!
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
10
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;
}
Unlock Deck
Unlock for access to all 99 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 99 flashcards in this deck.
Unlock Deck
k this deck
12
Assuming that the user provides 303 as input, what is the output of the following code snippet?
Int x;
Int y;
X = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
Y = in.nextInt();
If (y > 300)
{
X = y;
}
Else
{
X = 0;
}
System.out.println("x: " + x);

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 99 flashcards in this deck.
Unlock Deck
k this deck
13
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 99 flashcards in this deck.
Unlock Deck
k this deck
14
What kind of operator is the <= operator?

A) Ternary
B) Arithmetic
C) Inequality
D) Relational
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
15
Assuming that a user enters 25 as the value for x, what is the output of the following code snippet?
Int x = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
X = in.nextInt();
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 99 flashcards in this deck.
Unlock Deck
k this deck
16
What is the output of the following code snippet if the input is 25?
Int i = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
I = in.nextInt();
If (i > 25)
{
I++;
}
Else
{
I--;
}
System.out.print(i);

A) 24
B) 25
C) 26
D) 27
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
17
In Java, which of the following orderings is used to compare strings?

A) Lexicographic
B) Semantic
C) Alphabetic
D) Syntactic
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
18
The following code snippet contains an error. What is the error?
If (cost > 100);
{
Cost = cost - 10;
}
System.out.println("Discount cost: " + cost);

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 99 flashcards in this deck.
Unlock Deck
k this deck
19
What can be done to improve the following code fragment?
If ((counter % 10) == 0)
{
System.out.println("Counter is divisible by ten: " + counter);
Counter++;
}
Else
{
System.out.println("Counter is not divisible by ten: "
+ counter);
Counter++;
}

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 99 flashcards in this deck.
Unlock Deck
k this deck
20
Assuming that the user provides 99 as input, what is the output of the following code snippet?
Int a;
Int b;
A = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number: ");
B = in.nextInt();
If (b > 300)
{
A = b;
}
Else
{
A = 0;
}
System.out.println("a: " +
A) a: 0

A);
B) a: 99
C) a: 100
D) a: 300
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
21
Consider the following code snippet. Assuming that the user inputs 75 as the age, what is the output?
Int age = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your age: ");
Age = in.nextInt();
If (age < 10)
{
System.out.print("Child ");
}
If (age < 30)
{
System.out.print("Young adult ");
}
If (age < 70)
{
System.out.print("Old ");
}
If (age < 100)
{
System.out.print("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 99 flashcards in this deck.
Unlock Deck
k this deck
22
What is the value of the price variable after the following code snippet is executed?
Int price = 42;
If (price < 40)
{
Price = price + 10;
}
If (price > 30)
{
Price = price * 2;
}
If (price < 100)
{
Price = price - 20;
}

A) 42
B) 52
C) 84
D) 64
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
23
Consider the following code snippet. What is the potential problem with the if statement?
Double average;
Average = (g1 + g2 + g3 + g4) / 4.0;
If (average == 90.0)
{
System.out.println("You earned an A in the class!");
}

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 99 flashcards in this deck.
Unlock Deck
k this deck
24
Assuming that a user enters 5 as the value for num, what is the output of the following code snippet?
Int num = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num = in.nextInt();
If (num < 50)
{
Num = num + 5;
}
If (num < 10)
{
Num = num - 2;
}
If (num > 5)
{
Num++;
}
Else
{
Num--;
}
System.out.println(num);

A) 0
B) 9
C) 5
D) 11
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
25
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 99 flashcards in this deck.
Unlock Deck
k this deck
26
What is the output of the following code snippet?
String str1 = "her";
String str2 = "cart";
If (str1.compareTo(str2) < 0)
{
System.out.print(str2);
}
Else
{
System.out.print(str1);
}

A) her
B) hercart
C) cart
D) carther
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following options is a legally correct expression for inverting a condition?

A) if (!(a == 10))
B) if (!a == 10)
C) if (a !== 10)
D) if (a ! 10)
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
28
Write an if-statement condition that is true if 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 99 flashcards in this deck.
Unlock Deck
k this deck
29
What is the problem with the following if statement?
Double count = 15.0;
If (count / 3.0)
{
System.out.println("The value of count is ");
}

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 99 flashcards in this deck.
Unlock Deck
k this deck
30
Which condition, when supplied in the if statement below in place of (. . .), will correctly protect against division by zero?
If (. . .)
{
Result = grade / num;
System.out.println("Just avoided division by zero!");
}

A) (grade == 0)
B) ((grade / num) == 0)
C) (num == 0)
D) (num != 0)
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
31
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?
Int num1 = 0;
Int num2 = 0;
Int num3 = 0;
Int num4 = 0;
Int num5 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num1 = in.nextInt();
System.out.print("Enter a number: ");
Num2 = in.nextInt();
If (num1 < num2)
{
Num3 = num1;
}
Else
{
Num3 = num2;
}
If (num1 < num2 + 10)
{
Num4 = num1;
}
Else if (num1 < num2 + 20)
{
Num5 = num1;
}
System.out.println("num1 = " + num1 + " num2 = " + num2
+ " num3 = " + num3 + " num4 = " + num4
+ " num5 = " + num5);

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 99 flashcards in this deck.
Unlock Deck
k this deck
32
What is the output of the following code snippet?
Int num = 100;
If (num != 100)
{
System.out.println("100");
}
Else
{
System.out.println("Not 100");
}

A) There is no output due to compilation errors.
B) 100
C) Not 100
D) 100 Not 100
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
33
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 99 flashcards in this deck.
Unlock Deck
k this deck
34
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 99 flashcards in this deck.
Unlock Deck
k this deck
35
Assuming that the user enters 60 as the input, what is the output after running the following code snippet?
Int num = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num = in.nextInt();
If (num < 10)
{
System.out.println("Too small!");
}
Else if (num < 50)
{
System.out.println("Intermediate!");
}
Else if (num < 100)
{
System.out.println("High!");
}
Else
{
System.out.println("Too high!");
}

A) Too small!
B) Intermediate!
C) High!
D) Too high!
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
36
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 99 flashcards in this deck.
Unlock Deck
k this deck
37
What is the output of the following code snippet?
Int s1 = 20;
If (s1 <= 20)
{
System.out.print("1");
}
If (s1 <= 40)
{
System.out.print("2");
}
If (s1 <= 20)
{
System.out.print("3");
}

A) 1
B) 2
C) 3
D) 123
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
38
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 99 flashcards in this deck.
Unlock Deck
k this deck
39
Suppose you want to write an if statement with multiple alternatives to print out the single tax bracket that someone is in, based on their income. Assume the integer variable income holds the annual income. What is wrong with the following if statement?
If (income < 10000)
{
System.out.println("Lowest tax bracket");
}
If (income < 20000)
{
System.out.println("Low-Middle tax bracket");
}
If (income < 30000)
{
System.out.println("Middle tax bracket");
}
System.out.println("High tax bracket");

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 tax brackets
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following code snippet:
Int number = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Number = in.nextInt();
If (number > 30) { . . . }
Else if (number > 20) { . . .. }
Else if (number > 10) { . . . }
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 99 flashcards in this deck.
Unlock Deck
k this deck
41
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 multiple else branches inside a nested if statement.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
42
When testing code for correctness, it always makes sense to

A) Test all cases
B) Identify boundary cases and test them
C) Check all cases by hand
D) Assume invalid input will never occur
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following operators is used to invert a conditional statement?

A) !
B) !=
C) ||
D) ?
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
44
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 (cost < 70) { . . . }
Else { . . . }
If (tax_rate < 0.10) { . . . }
D) if (cost < 70) { . . . }
{
Else
{
If (tax_rate < 0.10) { . . . }
}
}
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
45
When drawing flowcharts, unconstrained branching and merging can lead to

A) So-called "spaghetti code"
B) A better design
C) Intuitive understanding of the flow of control
D) Clear visualization of the problem solution
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following variables is used to store a condition that can be either true or false?

A) Algebraic
B) Logical
C) Boolean
D) Conditional
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following expressions represents a legal way of checking whether a value assigned to the num variable falls in the range 100 to 200?

A) if (num >= 200 && num <= 100)
B) if (num >= 100 && num <= 200)
C) if (num >= 100 || num <= 200)
D) if (num >= 200 || num <= 100)
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following expressions represents a legal way of checking whether a value for the num variable is either less than 100 or more than 200?

A) if (num <= 100 && num >= 200)
B) if (num < 100 && num > 200)
C) if (num < 100 || num > 200)
D) if (num <= 100 || num >= 200)
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
49
Which of the following operators is NOT a relational operator?

A) <=
B) +=
C) !=
D) ==
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
50
What is the value of the magicPowers variable after executing the following code snippet?
String magicPowers = "";
Int experienceLevel = 9;
If (experienceLevel > 10)
{
MagicPowers = magicPowers + "Golden sword ";
}
If (experienceLevel > 8)
{
MagicPowers = magicPowers + "Shining lantern ";
}
If (experienceLevel > 2)
{
MagicPowers = magicPowers + "Magic beans ";
}

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 99 flashcards in this deck.
Unlock Deck
k this deck
51
Assuming that a user enters 5 as the age, what is the output of the following code snippet?
Int age = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your age: ");
Age = in.nextInt();
If (age < 10)
{
System.out.println("Kid");
}
If (age < 30)
{
System.out.print("Young");
}
If (age < 70)
{
System.out.print("Aged");
}
If (age < 100)
{
System.out.print("Old");
}

A) Kid
B) Kid
Young
C) Kid
YoungAged
D) Kid
YoungAgedOld
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
52
What is the value of num after you run the following code snippet?
Int num = 100;
If (num <= 100)
{
Num++;
}
If (num <= 200)
{
Num--;
}
If (num <= 300)
{
Num++;
}
If (num <= 400)
{
Num--;
}
If (num <= 500)
{
Num++;
}

A) 99
B) 100
C) 101
D) 102
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
53
Assuming that a user enters 56 for age, what is the output of the following code snippet?
Int age = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your age: ");
Age = in.nextInt();
If (age < 13)
{
System.out.println("Kid!");
}
If (age >= 13 && age < 19)
{
System.out.println("Teen!");
}
If (age >= 19 && age < 30)
{
System.out.println("Young!");
}
If (age >= 30 && age < 50)
{
System.out.println("Adult!");
}
If (age >= 50)
{
System.out.println("Old!");
}

A) Teen!
B) Young!
C) Adult!
D) Old!
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
54
What is the output of the following code snippet?
Boolean attendance = false;
String str = "Unknown";
Attendance = !(attendance);
If (!attendance)
{
Str = "False";
}
If (attendance)
{
Attendance = false;
}
If (attendance)
{
Str = "True";
}
Else
{
Str = "Maybe";
}
System.out.println(str);

A) False
B) True
C) Unknown
D) Maybe
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
55
What is the output of the following code snippet?
Final int MIN_SPEED = 45;
Final int MAX_SPEED = 65;
Int speed = 55;
If (!(speed < MAX_SPEED))
{
Speed = speed - 10;
}
If (!(speed > MIN_SPEED))
{
Speed = speed + 10;
}
System.out.println(speed);

A) 45
B) 55
C) 65
D) 50
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
56
What is the output of the following code snippet?
Int num = 100;
If (num > 100);
{
Num = num - 10;
}
System.out.println(num);

A) 90
B) 100
C) 99
D) 101
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
57
The flow chart shows the order in which steps should be executed, and the diamond-shaped boxes indicate

A) input
B) algorithms
C) tasks
D) conditional tests
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
58
Assuming that a user enters 64 as his score, what is the output of the following code snippet?
Int score = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter your score: ");
Score = in.nextInt();
If (score < 40)
{
System.out.println("F");
}
Else if (score >= 40 || score < 50)
{
System.out.println("D");
}
Else if (score >= 50 || score < 60)
{
System.out.println("C");
}
Else if (score >= 60 || score < 70)
{
System.out.println("B");
}
Else if (score >= 70 || score < 80)
{
System.out.println("B+");
}
Else
{
System.out.println("A");
}

A) D
B) C
C) B
D) A
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
59
Which of the following operators is used to combine two Boolean conditions?

A) ##
B) $$
C) %%
D) &&
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
60
Consider the following code snippet:
Boolean attendance = true;
Boolean failed = false;
Which of the following if statement s includes a condition that evaluates to true?

A) if (attendance == "true") { . . . }
B) if (attendance) { . . . }
C) if (failed) { . . . }
D) if (attendance == failed) { . . . }
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
61
What is the output of the following code snippet?
String someString1 = "his";
String someString2 = "cycle";
If (someString1.compareTo(someString2) < 0)
{
System.out.println(someString2);
}
Else
{
System.out.println(someString1);
}

A) his
B) hiscycle
C) cycle
D) There is no output due to compilation errors.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
62
Consider the following code snippet:
Int score = 0;
Double price = 100;
If (score > 0 && price < 200 && price / score > 10)
{
System.out.println("buy");
}
Which of the following statements is true on the basis of this code snippet?

A) The output is buy.
B) The code snippet compiles and runs, but there is no output.
C) The code snippet doesn't compile.
D) The code snippet causes a divide-by-zero error.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
63
What is the output of the following code snippet?
Int age = 25;
If (age > 30)
{
System.out.println("You are wise!");
}
Else
{
System.out.println("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 99 flashcards in this deck.
Unlock Deck
k this deck
64
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 (cost >= 150)
{
ServiceCharge = 0.15 * cost;
}
B) double serviceCharge = 0.15 * cost;
If (cost <= 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 99 flashcards in this deck.
Unlock Deck
k this deck
65
Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet?
Int price = 0;
String status = "";
Scanner in = new Scanner(System.in);
System.out.print("Please enter object's price: ");
Price = in.nextInt();
If (price >= 50)
{
Status = "reasonable";
If (price >= 75)
{
Status = "costly";
}
}
Else
{
Status = "inexpensive";
If (price <= 25)
{
Status = "reasonable";
}
}

A) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)
B) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)
C) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)
D) <strong>Assuming that a user enters 22 as the price of an object, which of the following hand-trace tables is valid for the given code snippet? Int price = 0; String status = ; Scanner in = new Scanner(System.in); System.out.print(Please enter object's price: ); Price = in.nextInt(); If (price >= 50) { Status = reasonable; If (price >= 75) { Status = costly; } } Else { Status = inexpensive; If (price <= 25) { Status = reasonable; } }</strong> A)   B)   C)   D)
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
66
Which of the following coding techniques can hand-tracing be applied to?

A) Pseudocode
B) Java code
C) Both pseudocode and Java code
D) Neither pseudocode nor Java code
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
67
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?
Int num1 = 0;
Int num2 = 0;
Int num3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num1 = in.nextInt();
System.out.print("Enter a number: ");
Num2 = in.nextInt();
System.out.print("Enter a number: ");
Num3 = in.nextInt();
If (num1 > num2)
{
If (num1 > num3)
{
System.out.println(num1);
}
Else
{
System.out.println(num3);
}
}
Else
{
If (num2 > num3)
{
System.out.println(num2);
}
Else
{
System.out.println(num3);
}
}

A) 0
B) 10
C) 20
D) 30
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
68
Which of the following conditions tests whether the user enters an integer value that will then be assigned to the floor variable?
Int floor = 0;
Scanner in = new Scanner(System.in);
System.out.print("Floor: ");
( ) . . )
Floor = in.nextInt();

A) if (in.nextInt(floor))
B) if (in.hasNextInt())
C) if (in.fail)
D) if (in.nextInt())
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
69
What is the output of the following code snippet?
Int num = 100;
If (num < 100)
{
If (num < 50)
{
Num = num - 5;
}
Else
{
Num = num - 10;
}
}
Else
{
If (num > 150)
{
Num = num + 5;
}
Else
{
Num = num + 10;
}
}
System.out.println(num);

A) 95
B) 100
C) 105
D) 110
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
70
Which of the following operators compare using short-circuit evaluation?

A) ++
B) -
C) &&
D) ==
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
71
Assuming that a valid price should be between 30 and 50, does the following code snippet test this condition correctly?
Final int MIN_PRICE = 30;
Final int MAX_PRICE = 50;
Int price = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter the price: ");
Price = in.nextInt();
If (price < MIN_PRICE)
{
System.out.println("Error: The price is too low.");
}
Else if (price > MAX_PRICE)
{
System.out.println("Error: The price is too high.");
}
Else
{
System.out.println("The price entered is in the valid price range.");
}

A) This code snippet ensures that the price value is between 30 and 50.
B) This code snippet only ensures that the price value is greater than 30.
C) This code snippet only ensures that the price value is less than 50.
D) This code snippet ensures that the price value is either less than 30 or greater than 50.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
72
Assuming that a user enters 45, 78, and then 12, what is the output of the following code snippet?
Int num1 = 0;
Int num2 = 0;
Int num3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
Num1 = in.nextInt();
System.out.print("Enter a number: ");
Num2 = in.nextInt();
System.out.print("Enter a number: ");
Num3 = in.nextInt();
If (!(num1 > num2 && num1 > num3))
{
System.out.println(num1);
}
Else if (!(num2 > num1 && num2 > num3))
{
System.out.println(num2);
}
Else if (!(num3 > num1 && num3 > num2))
{
System.out.println(num3);
}

A) 12
B) 45
C) 78
D) There is no output due to compilation errors.
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
73
What is the output of the following code snippet?
Int x = 50;
If (x > 100)
{
X++;
}
Else
{
X--;
}
System.out.println(x);

A) 49
B) 50
C) 51
D) 52
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
74
What is the output of the following code snippet?
Int digit = 500;
If (digit != 500)
{
System.out.println("500");
}
Else
{
System.out.println("Not 500");
}

A) There is no output due to compilation errors.
B) 500
C) Not 500
D) 500
Not 500
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
75
Which of the following options checks that city is neither Chicago nor Dallas?

A) if (city != "Chicago" || city != "Dallas")
B) if !(city == "Chicago" || city == "Dallas")
C) if !(city == "Chicago" && city == "Dallas")
D) if (city != "Chicago" || city == "Dallas")
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
76
Assuming that the user provides 49 as input, what is the output of the following code snippet?
Int x = 0;
Int y = 0;
System.out.print("Please enter y: ");
Scanner in = new Scanner(System.in);
Y = in.nextInt();
If (y > 50);
{
X = y;
}
System.out.println("x: " + x);

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 99 flashcards in this deck.
Unlock Deck
k this deck
77
Which of the following options refers to the technique of simulating program execution on a sheet of paper?

A) Compiling
B) Prototyping
C) Tracing
D) Debugging
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
78
Which of the following statements can be used to validate that the user input for the floor variable is between 0 and 20 inclusive?

A) if (floor >= 0 && floor <= 20)
B) if (floor >= 0 || floor <= 20)
C) if (floor <= 0 && floor >= 20)
D) if (floor <= 0 || floor >= 20)
Unlock Deck
Unlock for access to all 99 flashcards in this deck.
Unlock Deck
k this deck
79
Assuming that the user provides 3 as input, what is the output of the following code snippet?
Int x;
Int y;
X = 0;
System.out.print("Please enter y: ");
Scanner in = new Scanner(System.in);
Y = in.nextInt();
If (y > 0)
{
X = 2 * y;
}
Else
{
X = 2 + x;
}
System.out.println("x: " + x);

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 99 flashcards in this deck.
Unlock Deck
k this deck
80
What is the output of the following code snippet?
Double salary = 55000;
Double cutOff = 65000;
Double minSalary = 40000;
If (minSalary > salary)
{
System.out.println("Minimum salary requirement is not met.");
}
If (cutOff < salary)
{
System.out.println("Maximum salary limit is exceeded.");
}
Else
{
System.out.println("Salary requirement is met.");
}

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 99 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 99 flashcards in this deck.