Deck 3: Decision Structures

Full screen (f)
exit full mode
Question
This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets:

A) ASCII
B) Unicode
C) Java
D) None of the above
Use Space or
up arrow
down arrow
to flip the card.
Question
What will be the value of x after the following code is executed?
Int x = 75;
Int y = 60;
If (x > y)
X = x - y;

A) 75
B) 15
C) 60
D) 135
Question
If chr is a character variable, which of the following if statements is written correctly?

A) if (chr = "a")
B) if (chr == "a")
C) if (chr = 'a')
D) if (chr == 'a')
Question
What will be the value of ans after the following code has been executed?
Int ans = 10;
Int x = 65;
Int y = 55;
If (x >= y)
Ans = x + y;

A) 10
B) 120
C) 100
D) No value, there is a syntax error.
Question
In most editors, you are indenting by one level each time that you press this key:

A) Tab
B) Shift
C) Alt
D) Space
Question
What would be the value of bonus after the following statements are executed?
Int bonus, sales = 1250;
If (sales > 1000)
Bonus = 100;
If (sales > 750)
Bonus = 50;
If (sales > 500)
Bonus = 25;
Else
Bonus = 0;

A) 100
B) 500
C) 25
D) 0
Question
This type of operator determines whether a specific relationship exists between two values:

A) Logical
B) Mathematical
C) Unary
D) Relational
Question
What would be the value of bonus after the following statements are executed?
Int bonus, sales = 85000;
Char dept = 'S';
If (sales > 100000)
If (dept == 'R')
Bonus = 2000;
Else
Bonus = 1500;
Else if (sales > 75000)
If (dept == 'R')
Bonus = 1250;
Else
Bonus = 1000;
Else
Bonus = 0;

A) 2000
B) 1500
C) 1250
D) 1000
Question
In Java, when a character is stored in memory, it is actually stored as a(n):

A) Unicode number
B) ASCII character code
C) EBCDIC character code
D) Morse code
Question
The ________ statement is used to make simple decisions in Java.

A) do/while
B) for
C) branch
D) if
Question
Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

A) ((x >= 500 && x <= 650) && (y != 1000))
B) ((x > 500 AND x < 650) OR !(y.equal(1000)))
C) ((x > 500 && x < 650) || (y != 1000))
D) ((x < 500 && x > 650) || !(y == 1000))
Question
A block of code is enclosed in a set of:

A) braces { }
B) parentheses ( )
C) double quotes " "
D) brackets [ ]
Question
A flag may have the values:

A) 0 or 1
B) +1 or -1
C) true or False
D) of any character
Question
What will be the value of ans after the following code has been executed?
Int x = 90, y = 55, ans = 10;
If ( x == y);
Ans *= 2;

A) 10
B) 145
C) 20
D) No value, there is a syntax error.
Question
A Boolean expression is one that is either:

A) true or False
B) x or y
C) Positive or negative
D) None of the above
Question
Which one of the following is the not equal operator?

A) <>
B) NOT
C) *&
D) !=
Question
Which of the following expressions will determine whether x is less than or equal to y?

A) x > y
B) x =< y
C) x <= y
D) x >= y
Question
What will be the values of ans, x, and y after the following statements are executed?
Int ans = 35, x = 50, y =50;
If ( x >= y)
{
Ans = x + 10;
X -=y;
}
Else
{
Ans = y + 10;
Y += x;
}

A) ans = 60, x = 50, y =100
B) ans = 60, x =0, y =50
C) ans = 45, x = 50, y = 0
D) ans = 45, x = 50, y = 50
Question
What will be the value of bonus after the following code is executed?
Int bonus, sales = 10000;
If (sales < 5000)
Bonus = 200;
Else if (sales < 7500)
Bonus = 500;
Else if (sales < 10000)
Bonus = 750;
Else if (sales < 20000)
Bonus = 1000;
Else
Bonus = 1250;

A) 200
B) 500
C) 750
D) 1000
E) 1250
Question
If you prematurely terminate an if statement with a semicolon, the compiler will:

A) Not display an error message
B) Assume you are placing a null statement there
C) All of the above
D) None of the above
Question
Enclosing a group of statements inside a set of braces creates a:

A) block of statements
B) boolean expression
C) loop
D) nothing, it is just for readability
Question
Which of the following correctly tests the char variable chr to determine whether it is NOT equal to the character B?

A) if (chr > 'B')
B) if (chr < 'B')
C) if (chr != 'B')
D) if (chr != "B")
Question
What will be the value of pay after the following statements are executed?
Int hours = 45;
Double pay, payRate = 10.00;
Pay = hours <= 40 ?
Hours * payRate :
40 * payRate + (hours - 40) * payRate * 1.5;

A) 400.00
B) 450.00
C) 465.00
D) 475.00
Question
Which of the following will format 12.78 to display as 12.8%?

A) System.out.printf("%2.1d%", 12.78);
B) System.out.printf("%.2f%%", 12.78);
C) System.out.printf("%1.2d%", 12.78);
D) System.out.printf("%.1f%%", 12.78);
Question
What will be the values of ans, x, and y after the following statements are executed?
Int ans = 0, x = 15, y =25;
If ( x >= y)
{
Ans = x + 10;
X -=y;
}
Else
{
Ans = y + 10;
Y += x;
}

A) ans = 0, x = 15, y = 25
B) ans = 25, x = -10, y = 25
C) ans = 35, x = 15, y = 40
D) ans = 25, x = 15, y = 40
Question
What will be printed when the following code is executed?
Double x = 45678.259;
System.out.printf("%,.2f", x);

A) 45678.259
B) 0,045,678.26
C) 45,678.26
D) 45,678.3
Question
________ works like this: If the expression on the left side of the && operator is False, the expression the right side will not be checked.

A) Short-circuit evaluation
B) Reverse logic
C) Boolean logic
D) Relational evaluation
Question
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

A) (str1.equalsIgnoreCase(str2))
B) (str1.compareToIgnoreCase(str2) == 0)
C) Only A
D) A and B
Question
In an if/else statement, if the boolean expression is False:

A) the first statement or block is executed
B) the statement or block following the else is executed
C) all statements or blocks are executed
D) no statements or blocks are executed
Question
The expression tested by an if statement must evaluate to:

A) 0 or 1
B) +1 or -1
C) true or False
D) t or f
Question
What would be the value of discountRate after the following statements are executed?
Double discountRate = 0.0;
Int purchase = 100;
If (purchase > 1000)
DiscountRate = .05;
Else if (purchase > 750)
DiscountRate = .03;
Else if (purchase > 500)
DiscountRate = .01;

A) )05
B) )03
C) )01
D) 0.0
Question
What is the value of ans after the following code has been executed?
Int x = 35;
Int y = 20, ans = 80;
If (x < y);
Ans += y;

A) 80
B) 100
C) 35
D) 55
Question
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)

A) 1, 2, and 3 will all work
B) 2
C) 3
D) 2 and 3
Question
This is a boolean variable that signals when some condition exists in the program:

A) Sentinel
B) Block
C) Flag
D) Case
Question
What would be the value of x after the following statements were executed?
Int x = 10;
Switch (x)
{
Case 10:
X += 15;
Case 12:
X -= 5;
Break;
Default:
X *= 3;
}

A) 5
B) 20
C) 25
D) 30
Question
These operators use two operands:

A) Unary
B) Binary
C) Tertiary
D) None of the above
Question
What would be the value of discountRate after the following statements are executed?
Double discountRate = 0.0;
Int purchase = 1250;
If (purchase > 1000)
DiscountRate = .05;
If (purchase > 750)
DiscountRate = .03;
If (purchase > 500)
DiscountRate = .01;
Else
DiscountRate = 0;

A) )05
B) )03
C) )01
D) 0
Question
What is the value of x after the following code has been executed?
Int x = 75;
Int y = 90;
If ( x != y)
X += y;

A) 75
B) 90
C) 15
D) 165
Question
What would be the value of discountRate after the following statements are executed?
Double discountRate = 0.0;
Int purchase = 1250;
Char cust = 'N';
If (purchase > 1000)
If (cust == 'Y')
DiscountRate = .05;
Else
DiscountRate = .04;
Else if (purchase > 750)
If (cust == 'Y')
DiscountRate = .04;
Else
DiscountRate = .03;
Else
DiscountRate = 0;

A) )05
B) )04
C) )03
D) 0
Question
What is the value of ans after the following code has been executed?
Int x = 40;
Int y = 40;
Int ans = 0;
If (x = y)
Ans = x + 10;

A) 50
B) 80
C) 30
D) No value, this is a syntax error.
Question
Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000?

A) ((x >= 500 && x <650) && (y != 1000))
B) ((x <= 500 OR x > 650) AND !(y.equal(1000)))
C) ((x >= 500 || x < 650) || (y != 1000))
D) ((x <= 500 || x > 650) && !(y == 1000))
Question
The switch statement is a:

A) Multiple alternative decision structure
B) Nested decision structure
C) Sequence structure
D) Test expression
Question
Programs never need more than one path of execution.
Question
Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression that is most likely False is on the left of the && operator.
Question
When testing for character values, the switch statement does not test for the case of the character.
Question
Which of the following will format 12.7801 to display as $12.78?

A) System.out.printf("$%,.2f", 12.7801);
B) System.out.printf("%f", 12.7801);
C) System.out.printf("%.2f $$", 12.7801);
D) System.out.printf("$d", 12.7801);
Question
What does the following code display?
Int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);

A) %d %d
B) 9 12
C) %d 9
D) %9 %12
Question
Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL the world's alphabets.
Question
An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statement.
Question
What will be printed when the following code is executed?
Int y = 10;
If ( y == 10)
{
Int x = 30;
X += y;
}
System.out.print("x = ");
System.out.print(x);

A) x = 30
B) x = 40
C) x = 20
D) x is unknown when the last statement is executed.
Question
What would be the value of discountRate after the following statements are executed?
Double discountRate;
Char custType = 'B';
Switch (custType)
{
Case 'A':
DiscountRate = .08;
Break;
Case 'B':
DiscountRate = .06;
Case 'C':
DiscountRate = .04;
Default:
DiscountRate = 0.0;
}

A) )08
B) )06
C) )04
D) 0.0
Question
The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is False.
Question
What will be the value of charges after the following code is executed?
Double charges, rate = 7.00;
Int time = 180;
Charges = time <= 119 ?
Rate * 2 :
Time / 60.0 * rate;

A) 7.00
B) 14.00
C) 21.00
D) 28.00
Question
If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal?
(1)(str1 == str2)
(2) str1.equals(str2)
(3)(str1.compareTo(str2) == 0)

A) 1, 2, and 3 will all work
B) 1 and 2
C) 1 and 3
D) 2 and 3
Question
Because the || operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left.
Question
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
Question
What does the following code display?
Double x = 12.3798146;
System.out.printf("%.2f\n", x);

A) 123798146
B) 1238
C) %12.38
D) 12.38
Question
What will be printed when the following code is executed?
Double x = 45678.259;
String output = String.format("%,.1f", x);
System.out.println(output);

A) 45678.259
B) 45,678.259
C) 45,678.26
D) 45,678.3
Question
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Question
An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement.
Question
The String.format method works exactly like the System.out.printf method, except that it does not display the formatted string on the screen.
Question
In a switch statement, each of the case values must be unique.
Question
The System.out.printf method formats a string and displays it in the console window.
Question
In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/64
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Decision Structures
1
This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets:

A) ASCII
B) Unicode
C) Java
D) None of the above
B
2
What will be the value of x after the following code is executed?
Int x = 75;
Int y = 60;
If (x > y)
X = x - y;

A) 75
B) 15
C) 60
D) 135
B
3
If chr is a character variable, which of the following if statements is written correctly?

A) if (chr = "a")
B) if (chr == "a")
C) if (chr = 'a')
D) if (chr == 'a')
D
4
What will be the value of ans after the following code has been executed?
Int ans = 10;
Int x = 65;
Int y = 55;
If (x >= y)
Ans = x + y;

A) 10
B) 120
C) 100
D) No value, there is a syntax error.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
5
In most editors, you are indenting by one level each time that you press this key:

A) Tab
B) Shift
C) Alt
D) Space
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
6
What would be the value of bonus after the following statements are executed?
Int bonus, sales = 1250;
If (sales > 1000)
Bonus = 100;
If (sales > 750)
Bonus = 50;
If (sales > 500)
Bonus = 25;
Else
Bonus = 0;

A) 100
B) 500
C) 25
D) 0
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
7
This type of operator determines whether a specific relationship exists between two values:

A) Logical
B) Mathematical
C) Unary
D) Relational
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
8
What would be the value of bonus after the following statements are executed?
Int bonus, sales = 85000;
Char dept = 'S';
If (sales > 100000)
If (dept == 'R')
Bonus = 2000;
Else
Bonus = 1500;
Else if (sales > 75000)
If (dept == 'R')
Bonus = 1250;
Else
Bonus = 1000;
Else
Bonus = 0;

A) 2000
B) 1500
C) 1250
D) 1000
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
9
In Java, when a character is stored in memory, it is actually stored as a(n):

A) Unicode number
B) ASCII character code
C) EBCDIC character code
D) Morse code
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
10
The ________ statement is used to make simple decisions in Java.

A) do/while
B) for
C) branch
D) if
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

A) ((x >= 500 && x <= 650) && (y != 1000))
B) ((x > 500 AND x < 650) OR !(y.equal(1000)))
C) ((x > 500 && x < 650) || (y != 1000))
D) ((x < 500 && x > 650) || !(y == 1000))
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
12
A block of code is enclosed in a set of:

A) braces { }
B) parentheses ( )
C) double quotes " "
D) brackets [ ]
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
13
A flag may have the values:

A) 0 or 1
B) +1 or -1
C) true or False
D) of any character
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
14
What will be the value of ans after the following code has been executed?
Int x = 90, y = 55, ans = 10;
If ( x == y);
Ans *= 2;

A) 10
B) 145
C) 20
D) No value, there is a syntax error.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
15
A Boolean expression is one that is either:

A) true or False
B) x or y
C) Positive or negative
D) None of the above
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
16
Which one of the following is the not equal operator?

A) <>
B) NOT
C) *&
D) !=
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following expressions will determine whether x is less than or equal to y?

A) x > y
B) x =< y
C) x <= y
D) x >= y
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
18
What will be the values of ans, x, and y after the following statements are executed?
Int ans = 35, x = 50, y =50;
If ( x >= y)
{
Ans = x + 10;
X -=y;
}
Else
{
Ans = y + 10;
Y += x;
}

A) ans = 60, x = 50, y =100
B) ans = 60, x =0, y =50
C) ans = 45, x = 50, y = 0
D) ans = 45, x = 50, y = 50
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
19
What will be the value of bonus after the following code is executed?
Int bonus, sales = 10000;
If (sales < 5000)
Bonus = 200;
Else if (sales < 7500)
Bonus = 500;
Else if (sales < 10000)
Bonus = 750;
Else if (sales < 20000)
Bonus = 1000;
Else
Bonus = 1250;

A) 200
B) 500
C) 750
D) 1000
E) 1250
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
20
If you prematurely terminate an if statement with a semicolon, the compiler will:

A) Not display an error message
B) Assume you are placing a null statement there
C) All of the above
D) None of the above
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
21
Enclosing a group of statements inside a set of braces creates a:

A) block of statements
B) boolean expression
C) loop
D) nothing, it is just for readability
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following correctly tests the char variable chr to determine whether it is NOT equal to the character B?

A) if (chr > 'B')
B) if (chr < 'B')
C) if (chr != 'B')
D) if (chr != "B")
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
23
What will be the value of pay after the following statements are executed?
Int hours = 45;
Double pay, payRate = 10.00;
Pay = hours <= 40 ?
Hours * payRate :
40 * payRate + (hours - 40) * payRate * 1.5;

A) 400.00
B) 450.00
C) 465.00
D) 475.00
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following will format 12.78 to display as 12.8%?

A) System.out.printf("%2.1d%", 12.78);
B) System.out.printf("%.2f%%", 12.78);
C) System.out.printf("%1.2d%", 12.78);
D) System.out.printf("%.1f%%", 12.78);
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
25
What will be the values of ans, x, and y after the following statements are executed?
Int ans = 0, x = 15, y =25;
If ( x >= y)
{
Ans = x + 10;
X -=y;
}
Else
{
Ans = y + 10;
Y += x;
}

A) ans = 0, x = 15, y = 25
B) ans = 25, x = -10, y = 25
C) ans = 35, x = 15, y = 40
D) ans = 25, x = 15, y = 40
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
26
What will be printed when the following code is executed?
Double x = 45678.259;
System.out.printf("%,.2f", x);

A) 45678.259
B) 0,045,678.26
C) 45,678.26
D) 45,678.3
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
27
________ works like this: If the expression on the left side of the && operator is False, the expression the right side will not be checked.

A) Short-circuit evaluation
B) Reverse logic
C) Boolean logic
D) Relational evaluation
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
28
To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

A) (str1.equalsIgnoreCase(str2))
B) (str1.compareToIgnoreCase(str2) == 0)
C) Only A
D) A and B
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
29
In an if/else statement, if the boolean expression is False:

A) the first statement or block is executed
B) the statement or block following the else is executed
C) all statements or blocks are executed
D) no statements or blocks are executed
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
30
The expression tested by an if statement must evaluate to:

A) 0 or 1
B) +1 or -1
C) true or False
D) t or f
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
31
What would be the value of discountRate after the following statements are executed?
Double discountRate = 0.0;
Int purchase = 100;
If (purchase > 1000)
DiscountRate = .05;
Else if (purchase > 750)
DiscountRate = .03;
Else if (purchase > 500)
DiscountRate = .01;

A) )05
B) )03
C) )01
D) 0.0
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
32
What is the value of ans after the following code has been executed?
Int x = 35;
Int y = 20, ans = 80;
If (x < y);
Ans += y;

A) 80
B) 100
C) 35
D) 55
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
33
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2?
(1) (str1 < str2)
(2) (str1.equals(str2) < 0)
(3) (str1.compareTo(str2) < 0)

A) 1, 2, and 3 will all work
B) 2
C) 3
D) 2 and 3
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
34
This is a boolean variable that signals when some condition exists in the program:

A) Sentinel
B) Block
C) Flag
D) Case
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
35
What would be the value of x after the following statements were executed?
Int x = 10;
Switch (x)
{
Case 10:
X += 15;
Case 12:
X -= 5;
Break;
Default:
X *= 3;
}

A) 5
B) 20
C) 25
D) 30
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
36
These operators use two operands:

A) Unary
B) Binary
C) Tertiary
D) None of the above
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
37
What would be the value of discountRate after the following statements are executed?
Double discountRate = 0.0;
Int purchase = 1250;
If (purchase > 1000)
DiscountRate = .05;
If (purchase > 750)
DiscountRate = .03;
If (purchase > 500)
DiscountRate = .01;
Else
DiscountRate = 0;

A) )05
B) )03
C) )01
D) 0
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
38
What is the value of x after the following code has been executed?
Int x = 75;
Int y = 90;
If ( x != y)
X += y;

A) 75
B) 90
C) 15
D) 165
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
39
What would be the value of discountRate after the following statements are executed?
Double discountRate = 0.0;
Int purchase = 1250;
Char cust = 'N';
If (purchase > 1000)
If (cust == 'Y')
DiscountRate = .05;
Else
DiscountRate = .04;
Else if (purchase > 750)
If (cust == 'Y')
DiscountRate = .04;
Else
DiscountRate = .03;
Else
DiscountRate = 0;

A) )05
B) )04
C) )03
D) 0
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
40
What is the value of ans after the following code has been executed?
Int x = 40;
Int y = 40;
Int ans = 0;
If (x = y)
Ans = x + 10;

A) 50
B) 80
C) 30
D) No value, this is a syntax error.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000?

A) ((x >= 500 && x <650) && (y != 1000))
B) ((x <= 500 OR x > 650) AND !(y.equal(1000)))
C) ((x >= 500 || x < 650) || (y != 1000))
D) ((x <= 500 || x > 650) && !(y == 1000))
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
42
The switch statement is a:

A) Multiple alternative decision structure
B) Nested decision structure
C) Sequence structure
D) Test expression
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
43
Programs never need more than one path of execution.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
44
Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression that is most likely False is on the left of the && operator.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
45
When testing for character values, the switch statement does not test for the case of the character.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following will format 12.7801 to display as $12.78?

A) System.out.printf("$%,.2f", 12.7801);
B) System.out.printf("%f", 12.7801);
C) System.out.printf("%.2f $$", 12.7801);
D) System.out.printf("$d", 12.7801);
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
47
What does the following code display?
Int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);

A) %d %d
B) 9 12
C) %d 9
D) %9 %12
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
48
Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL the world's alphabets.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
49
An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statement.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
50
What will be printed when the following code is executed?
Int y = 10;
If ( y == 10)
{
Int x = 30;
X += y;
}
System.out.print("x = ");
System.out.print(x);

A) x = 30
B) x = 40
C) x = 20
D) x is unknown when the last statement is executed.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
51
What would be the value of discountRate after the following statements are executed?
Double discountRate;
Char custType = 'B';
Switch (custType)
{
Case 'A':
DiscountRate = .08;
Break;
Case 'B':
DiscountRate = .06;
Case 'C':
DiscountRate = .04;
Default:
DiscountRate = 0.0;
}

A) )08
B) )06
C) )04
D) 0.0
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
52
The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is False.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
53
What will be the value of charges after the following code is executed?
Double charges, rate = 7.00;
Int time = 180;
Charges = time <= 119 ?
Rate * 2 :
Time / 60.0 * rate;

A) 7.00
B) 14.00
C) 21.00
D) 28.00
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
54
If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal?
(1)(str1 == str2)
(2) str1.equals(str2)
(3)(str1.compareTo(str2) == 0)

A) 1, 2, and 3 will all work
B) 1 and 2
C) 1 and 3
D) 2 and 3
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
55
Because the || operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
56
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
57
What does the following code display?
Double x = 12.3798146;
System.out.printf("%.2f\n", x);

A) 123798146
B) 1238
C) %12.38
D) 12.38
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
58
What will be printed when the following code is executed?
Double x = 45678.259;
String output = String.format("%,.1f", x);
System.out.println(output);

A) 45678.259
B) 45,678.259
C) 45,678.26
D) 45,678.3
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
59
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
60
An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
61
The String.format method works exactly like the System.out.printf method, except that it does not display the formatted string on the screen.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
62
In a switch statement, each of the case values must be unique.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
63
The System.out.printf method formats a string and displays it in the console window.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
64
In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.
Unlock Deck
Unlock for access to all 64 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 64 flashcards in this deck.