Deck 3: Decision Structures
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/52
Play
Full screen (f)
Deck 3: Decision Structures
1
What will be printed when the following code is executed? double x = 45678.259;
DecimalFormat formatter =
New DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
A) 45678.259
B) 0,045,678.26
C) 45,678.26
D) 45,678.3
DecimalFormat formatter =
New DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));
A) 45678.259
B) 0,045,678.26
C) 45,678.26
D) 45,678.3
C
2
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
Switch (x)
{
Case 10:
X += 15;
Case 12:
X -= 5;
Break;
Default:
X *= 3;
}
A) 5
B) 20
C) 25
D) 30
B
3
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
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
C
4
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
5
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
A) Unicode number
B) ASCII character code
C) EBCDIC character code
D) Morse code
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
6
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
7
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
Int y = 60;
If (x > y)
X = x - y;
A) 75
B) 15
C) 60
D) 135
Unlock Deck
Unlock for access to all 52 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
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 52 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following will format .1278 to display as 12.8%?
A) 000.0%
B) #0.00%
C) ###.##%
D) ##0.0%
A) 000.0%
B) #0.00%
C) ###.##%
D) ##0.0%
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
10
A flag may have the values
A) 0 or 1
B) +1 or -1
C) true or false
D) of any character
A) 0 or 1
B) +1 or -1
C) true or false
D) of any character
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
11
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')
A) if (chr = "a")
B) if (chr == "a")
C) if (chr = 'a')
D) if (chr == 'a')
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
12
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
13
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
(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 52 flashcards in this deck.
Unlock Deck
k this deck
14
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
15
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
A) (str1.equalsIgnoreCase(str2))
B) (str1.compareToIgnoreCase(str2)== 0)
C) Only a
D) a and b
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
16
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
A) x > y
B) x =< y
C) x < = y
D) x >= y
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
17
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
18
The _________ statement is used to make simple decisions in Java.
A) do/while
B) for
C) branch
D) if
A) do/while
B) for
C) branch
D) if
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
19
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 !))
C) ((x > 500 && x < 650)|| (y != 1000))
D) ((x < 500 && x > 650)|| !(y == 1000))
A) ((x >= 500 && x < = 650)&& (y != 1000))
B) ((x > 500 AND x < 650)OR !))
C) ((x > 500 && x < 650)|| (y != 1000))
D) ((x < 500 && x > 650)|| !(y == 1000))
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
20
A block of code is enclosed in a set of
A) braces { }
B) parentheses ( )
C) double quotes " "
D) brackets [ ]
A) braces { }
B) parentheses ( )
C) double quotes " "
D) brackets [ ]
Unlock Deck
Unlock for access to all 52 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
A) block of statements
B) boolean expression
C) loop
D) Nothing,it is just for readability
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
22
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
A) 0 or 1
B) +1 or -1
C) true or false
D) t or f
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
23
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
(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 52 flashcards in this deck.
Unlock Deck
k this deck
24
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
25
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
26
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
27
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
28
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
29
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 !))
C) ((x >= 500 || x < 650)|| (y != 1000))
D) ((x < = 500 || x > 650)&& !(y == 1000))
A) ((x >= 500 && x < 650)&& (y != 1000))
B) ((x < = 500 OR x > 650)AND !))
C) ((x >= 500 || x < 650)|| (y != 1000))
D) ((x < = 500 || x > 650)&& !(y == 1000))
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
30
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.
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 52 flashcards in this deck.
Unlock Deck
k this deck
31
What will be printed when the following code is executed? double x = 45678.259;
DecimalFormat formatter =
New DecimalFormat("#,##0.0");
System.out.println(formatter.format(x));
A) 45678.259
B) 45,678.259
C) 45,678.26
D) 45,678.3
DecimalFormat formatter =
New DecimalFormat("#,##0.0");
System.out.println(formatter.format(x));
A) 45678.259
B) 45,678.259
C) 45,678.26
D) 45,678.3
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following will format 12.78 to display as 012.8?
A) 000.0
B) #0.00
C) ###.#
D) ##0.0%
A) 000.0
B) #0.00
C) ###.#
D) ##0.0%
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
33
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
Int y = 90;
If ( x != y)
X += y;
A) 75
B) 90
C) 15
D) 165
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
34
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
35
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
36
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
37
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")
A) if (chr > 'B')
B) if (chr < 'B')
C) if (chr != 'B')
D) if (chr != "B")
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
38
This is a boolean variable that signals when some condition exists in the program
A) Sentinel
B) Block
C) Flag
D) Case
A) Sentinel
B) Block
C) Flag
D) Case
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
39
These operators are used to determine whether a specific relationship exists between two values.
A) Arithmetic
B) Relational
C) Syntactical
D) Assignment
A) Arithmetic
B) Relational
C) Syntactical
D) Assignment
Unlock Deck
Unlock for access to all 52 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 = 35;
Int y = 20,ans = 80;
If (x < y);
Ans += y;
A) 80
B) 100
C) 35
D) 55
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 52 flashcards in this deck.
Unlock Deck
k this deck
41
When testing for character values,the switch statement does not test for the case of the character.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
42
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
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 52 flashcards in this deck.
Unlock Deck
k this deck
43
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 52 flashcards in this deck.
Unlock Deck
k this deck
44
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 52 flashcards in this deck.
Unlock Deck
k this deck
45
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 52 flashcards in this deck.
Unlock Deck
k this deck
46
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 52 flashcards in this deck.
Unlock Deck
k this deck
47
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 52 flashcards in this deck.
Unlock Deck
k this deck
48
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 52 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 52 flashcards in this deck.
Unlock Deck
k this deck
50
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 52 flashcards in this deck.
Unlock Deck
k this deck
51
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 52 flashcards in this deck.
Unlock Deck
k this deck
52
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
System.out.printf("%.2f \ n",x);
A) 123798146
B) 1238
C) %12.38
D) 12.38
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck