Deck 4: Control Structures I: Selection

ملء الشاشة (f)
exit full mode
سؤال
The symbol >= is a logical operator.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
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.
سؤال
The operators = and == have the same order of precedence.
سؤال
A computer program will recognize both = and == as the equality operator.
سؤال
A program uses selection to implement a branch.
سؤال
In Java, case and switch are reserved words, but break is not a reserved word.
سؤال
Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true.
سؤال
Including a semicolon before the action statement in a one-way selection causes a syntax error.
سؤال
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.
سؤال
The expression !(x <= 0) is true only if x is a positive number.
سؤال
=! is a relational operator.
سؤال
In Java, || has a higher precedence than &&.
سؤال
All switch structures include default cases.
سؤال
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.
سؤال
Suppose P and Q are logical expressions. The logical expression P && Q is false if both P and Q are false.
سؤال
In Java, !, &&, and || are called logical operators.
سؤال
All switch cases include a break statement.
سؤال
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
سؤال
The expression 'A' <= 'B' evaluates to false while the expression 'A' < 'B' evaluates to true.
سؤال
When one control statement is located within another, it is said to be a controlled statement.
سؤال
The execution of a break statement in a switch statement terminates the switch statement.
سؤال
The method compareTo is part of the class String.
سؤال
Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1 and str2 point to the same String object.
سؤال
Which of the following is not a logical operator?

A) !
C) !=
B) ||
D) &&
سؤال
Two-way selection in Java is implemented using ____.

A) if statements
C) if...else statements
B) for loops
D) sequential statements
سؤال
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
سؤال
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
سؤال
What is the value of the expression above?

A) true
C) x
B) false
D) It cannot be determined.
سؤال
Suppose that you have the following statements. String str1 = "cat"; String str2 = "cats"; The statement str1.equals(str2); is true.
سؤال
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
سؤال
Which of the following is NOT a relational operator in Java?

A) <>
C) ==
B) <=
D) >
سؤال
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
سؤال
Based on the code above, what is the value of y if x = 4?

A) 2
C) 6
B) 4
D) 8
سؤال
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
سؤال
Which of the following is a relational operator?

A) =
C) !
B) ==
D) &&
سؤال
What does >= mean?

A) less than
C) less than or equal to
B) greater than
D) greater than or equal to
سؤال
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)
سؤال
Which of the following has the highest value?

A) '-'
C) 'H'
B) '5'
D) 'b'
سؤال
In a ____ control structure, the computer executes particular statements depending on some condition(s).

A) looping
C) selection
B) repetition
D) sequence
سؤال
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)
سؤال
Based on the code above, what is the value of y if x = 5?

A) 2
C) 6
B) 4
D) 8
سؤال
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
سؤال
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
سؤال
Based on the code above, what is the value of y if x = 9?

A) 2
C) 6
B) 4
D) 8
سؤال
Based on the code above, what is the value of y if x = 1?

A) 2
C) 6
B) 4
D) 8
سؤال
Based on the code above, what is the value of x?

A) 1
C) 5
B) 3
D) 12
سؤال
Based on the code above, what is the output if lastInitial = 'E'?

A) section 2
C) section 4
B) section 3
D) section 5
سؤال
Based on the code above, what is the output if lastInitial = 'C'?

A) section 1
C) section 3
B) section 2
D) section 5
سؤال
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
سؤال
The conditional operator ?: takes ____ arguments.

A) two
C) four
B) three
D) five
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
A program uses selection to implement a branch.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
In Java, case and switch are reserved words, but break is not a reserved word.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
Including a semicolon before the action statement in a one-way selection causes a syntax error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
The expression !(x <= 0) is true only if x is a positive number.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
=! is a relational operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
In Java, || has a higher precedence than &&.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
All switch structures include default cases.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
In Java, !, &&, and || are called logical operators.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
All switch cases include a break statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
The expression 'A' <= 'B' evaluates to false while the expression 'A' < 'B' evaluates to true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
When one control statement is located within another, it is said to be a controlled statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
The execution of a break statement in a switch statement terminates the switch statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
The method compareTo is part of the class String.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
Which of the following is not a logical operator?

A) !
C) !=
B) ||
D) &&
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
What is the value of the expression above?

A) true
C) x
B) false
D) It cannot be determined.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
Suppose that you have the following statements. String str1 = "cat"; String str2 = "cats"; The statement str1.equals(str2); is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which of the following is NOT a relational operator in Java?

A) <>
C) ==
B) <=
D) >
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which of the following is a relational operator?

A) =
C) !
B) ==
D) &&
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
Which of the following has the highest value?

A) '-'
C) 'H'
B) '5'
D) 'b'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
Based on the code above, what is the value of x?

A) 1
C) 5
B) 3
D) 12
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
The conditional operator ?: takes ____ arguments.

A) two
C) four
B) three
D) five
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.