Deck 4: Control Structures I: Selection
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/50
Play
Full screen (f)
Deck 4: Control Structures I: Selection
1
The symbol >= is a logical operator.
False
2
Suppose that you have the following code. int num = 10; if (num > 10) System.out.println(num); else System.out.println(num + 5); The output of this code is 5.
False
3
The operators = and == have the same order of precedence.
False
4
A computer program will recognize both = and == as the equality operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
A program uses selection to implement a branch.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
In Java, case and switch are reserved words, but break is not a reserved word.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Including a semicolon before the action statement in a one-way selection causes a syntax error.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
Suppose that the input is 6 and console is a Scanner object initialized to the standard input device. Consider the following code. int alpha = 7; int beta = console.nextInt(); switch (beta) {case 5: alpha = alpha + 1; case 6: alpha = alpha + 2; case 7: alpha = alpha + 3; default: alpha = alpha + 5;} System.out.print(alpha); The output of this code is 9.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The expression !(x <= 0) is true only if x is a positive number.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
=! is a relational operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
In Java, || has a higher precedence than &&.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
All switch structures include default cases.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Suppose that you have the following statements. int score; String grade; if (score >= 65) grade = "pass"; else grade = "fail"; If score is equal to 75, the value of grade is pass.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
Suppose P and Q are logical expressions. The logical expression P && Q is false if both P and Q are false.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
In Java, !, &&, and || are called logical operators.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
All switch cases include a break statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The expression 'A' <= 'B' evaluates to false while the expression 'A' < 'B' evaluates to true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
When one control statement is located within another, it is said to be a controlled statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
The execution of a break statement in a switch statement terminates the switch statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
The method compareTo is part of the class String.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1 and str2 point to the same String object.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following is not a logical operator?
A) !
C) !=
B) ||
D) &&
A) !
C) !=
B) ||
D) &&
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Two-way selection in Java is implemented using ____.
A) if statements
C) if...else statements
B) for loops
D) sequential statements
A) if statements
C) if...else statements
B) for loops
D) sequential statements
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following will cause a syntax error?
A) (10 < num) && (num < 30)
C) 10 < num && num < 25
B) 10 < num < 20
D) num > 10 && num < 40
A) (10 < num) && (num < 30)
C) 10 < num && num < 25
B) 10 < num < 20
D) num > 10 && num < 40
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
After the execution of the following code, what will be the value of num if the input values are 0 3? (Assume that console is a Scanner object initialized to the standard input device.) int num = console.nextInt(); if (num > 0) num = num + 13; else if (num >= 3) num = num + 15;
A) 0
C) 13
B) 3
D) 15
A) 0
C) 13
B) 3
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
What is the value of the expression above?
A) true
C) x
B) false
D) It cannot be determined.
A) true
C) x
B) false
D) It cannot be determined.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
Suppose that you have the following statements. String str1 = "cat"; String str2 = "cats"; The statement str1.equals(str2); is true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
What is the output of the following Java code? int x = 0; if (x > 0) System.out.println("positive "); System.out.println("zero "); System.out.println("negative");
A) zero
C) zero negative
B) negative
D) positive zero negative
A) zero
C) zero negative
B) negative
D) positive zero negative
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is NOT a relational operator in Java?
A) <>
C) ==
B) <=
D) >
A) <>
C) ==
B) <=
D) >
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
The output of the Java code: int alpha = 5; int beta = 4; switch (beta) {case 2: alpha = alpha + 2; case 4: alpha = alpha + 4; break; case 6: alpha = alpha + 6; default: alpha = alpha + 10;} System.out.print(alpha); is: 9
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Based on the code above, what is the value of y if x = 4?
A) 2
C) 6
B) 4
D) 8
A) 2
C) 6
B) 4
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Based on the code above, which part of the expression is not evaluated?
A) 2.5 >= 7
C) 2.5 >= 7 || 4 < y
B) 4 < y
D) 4 <= 8
A) 2.5 >= 7
C) 2.5 >= 7 || 4 < y
B) 4 < y
D) 4 <= 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following is a relational operator?
A) =
C) !
B) ==
D) &&
A) =
C) !
B) ==
D) &&
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
What does >= mean?
A) less than
C) less than or equal to
B) greater than
D) greater than or equal to
A) less than
C) less than or equal to
B) greater than
D) greater than or equal to
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Suppose that x is an int variable. Which of the following expressions always evaluates to false?
A) (x > 0) || (x <= 0)
C) (x > 0) && ( x <= 0)
B) (x > 0) || (x == 0)
D) (x >= 0) && (x == 0)
A) (x > 0) || (x <= 0)
C) (x > 0) && ( x <= 0)
B) (x > 0) || (x == 0)
D) (x >= 0) && (x == 0)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following has the highest value?
A) '-'
C) 'H'
B) '5'
D) 'b'
A) '-'
C) 'H'
B) '5'
D) 'b'
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
In a ____ control structure, the computer executes particular statements depending on some condition(s).
A) looping
C) selection
B) repetition
D) sequence
A) looping
C) selection
B) repetition
D) sequence
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following will cause a syntax error, if you are trying to compare x to 5?
A) if (x == 5)
C) if (x <= 5)
B) if (x = 5)
D) if (x >= 5)
A) if (x == 5)
C) if (x <= 5)
B) if (x = 5)
D) if (x >= 5)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
Based on the code above, what is the value of y if x = 5?
A) 2
C) 6
B) 4
D) 8
A) 2
C) 6
B) 4
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Suppose that you have the following code: int sum = 0; int num = 8; if (num < 0) sum = sum + num; else if (num > 5) sum = num + 15; After this code executes, what is the value of sum?
A) 0
C) 15
B) 8
D) 23
A) 0
C) 15
B) 8
D) 23
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
If str1 is "Hello" and str2 is "Hi", which of the following could not be a result of str1.compareTo(str2);?
A) -9
C) -1
B) -5
D) 1
A) -9
C) -1
B) -5
D) 1
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Based on the code above, what is the value of y if x = 9?
A) 2
C) 6
B) 4
D) 8
A) 2
C) 6
B) 4
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Based on the code above, what is the value of y if x = 1?
A) 2
C) 6
B) 4
D) 8
A) 2
C) 6
B) 4
D) 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Based on the code above, what is the value of x?
A) 1
C) 5
B) 3
D) 12
A) 1
C) 5
B) 3
D) 12
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
Based on the code above, what is the output if lastInitial = 'E'?
A) section 2
C) section 4
B) section 3
D) section 5
A) section 2
C) section 4
B) section 3
D) section 5
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
Based on the code above, what is the output if lastInitial = 'C'?
A) section 1
C) section 3
B) section 2
D) section 5
A) section 1
C) section 3
B) section 2
D) section 5
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What is the output of the following Java code? int x = 57; int y = 3; switch (x % 9) {case 0: case 1: y++; case 2: y = y - 2; break; case 3: y = y + 2; case 4: break; case 5: case 6: y = y + 3;} System.out.println(y);
A) 2
C) 6
B) 5
D) 57
A) 2
C) 6
B) 5
D) 57
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
The conditional operator ?: takes ____ arguments.
A) two
C) four
B) three
D) five
A) two
C) four
B) three
D) five
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck