Deck 4: Control Structures I: Selection
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
العب
ملء الشاشة (f)
Deck 4: Control Structures I: Selection
1
Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y is true.
True
2
=! is a relational operator.
False
3
In Java, !, &&, and || are called logical operators.
True
4
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
5
The expression 'A' 'B' evaluates to false while the expression 'A' 'B' evaluates to true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
All switch cases include a break statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
When one control statement is located within another, it is said to be a controlled statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 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
The symbol >= is a logical operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
In Java, case and switch are reserved words, but break is not a reserved word.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
A computer program will recognize both = and == as the equality operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
All switch structures include default cases.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
The expression !(x is true only if x is a positive number.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
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.
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
15
A program uses selection to implement a branch.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
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.
System.out.println(num);
else
System.out.println(num + 5);The output of this code is 5.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
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.
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
19
The operators = and == have the same order of precedence.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
In Java, || has a higher precedence than &&.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
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
B) negative
C) zero negative
D) positive zero negative
If (x > 0)
System.out.println("positive ");
System.out.println("zero ");
System.out.println("negative");
A) zero
B) negative
C) zero negative
D) positive zero negative
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
Which of the following has the highest value?
A) '-'
B) '5'
C) 'H'
D) 'b'
A) '-'
B) '5'
C) 'H'
D) 'b'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
'A' = 7 || 4 Based on the code above, which part of the expression is not evaluated?
A) 2.5 >= 7
B) 4
C) 2.5 >= 7 || 4
D) 4
A) 2.5 >= 7
B) 4
C) 2.5 >= 7 || 4
D) 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
Which of the following will cause a syntax error, if you are trying to compare x to 5?
A) if (x == 5)
B) if (x = 5)
C) if (x<= 5)
D) if (x >= 5)
A) if (x == 5)
B) if (x = 5)
C) if (x<= 5)
D) if (x >= 5)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
In a ____ control structure, the computer executes particular statements depending on some condition(s).
A) looping
B) repetition
C) selection
D) sequence
A) looping
B) repetition
C) selection
D) sequence
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
Two-way selection in Java is implemented using ____.
A) if statements
B) for loops
C) if...else statements
D) sequential statements
A) if statements
B) for loops
C) if...else statements
D) sequential statements
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
Which of the following is NOT a relational operator in Java?
A)< >
B)<
C) ==
D) >
A)< >
B)<
C) ==
D) >
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
The method compareTo is part of the class String.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
What does >= mean?
A) less than
B) greater than
C) less than or equal to
D) greater than or equal to
A) less than
B) greater than
C) less than or equal to
D) greater than or equal to
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
Suppose that x is an int variable. Which of the following expressions always evaluates to false?
A) (x > 0) || (x<=0)
B) (x > 0) || (x == 0)
C) (x > 0) && ( x<=0)
D) (x >= 0) && (x == 0)
A) (x > 0) || (x<=0)
B) (x > 0) || (x == 0)
C) (x > 0) && ( x<=0)
D) (x >= 0) && (x == 0)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which of the following is a relational operator?
A) =
B) ==
C) !
D) &&
A) =
B) ==
C) !
D) &&
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
Suppose that you have the following statements.String str1 = "cat";
String str2 = "cats";The statement str1.equals(str2); is true.
String str2 = "cats";The statement str1.equals(str2); is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
The execution of a break statement in a switch statement terminates the switch statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which of the following is not a logical operator?
A) !
B) ||
C) !=
D) &&
A) !
B) ||
C) !=
D) &&
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which of the following will cause a syntax error?
A) (10 < num) && (num < 30)
B) 10 < num <20
C) 10 < num && num < 25
D) num > 10 && num<40
A) (10 < num) && (num < 30)
B) 10 < num <20
C) 10 < num && num < 25
D) num > 10 && num<40
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
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
37
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 4?
A) 2
B) 4
C) 6
D) 8
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 4?
A) 2
B) 4
C) 6
D) 8
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
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
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
39
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
B) 3
C) 13
D) 15
Num = num + 13;
Else
If (num >= 3)
Num = num + 15;
A) 0
B) 3
C) 13
D) 15
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
'A' = 7 || 4 What is the value of the expression above?
A) true
B) false
C) x
D) It cannot be determined.
A) true
B) false
C) x
D) It cannot be determined.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
int x;
X = (1 'K' >= 'F') ? 5 : 12Based on the code above, what is the value of x?
A) 1
B) 3
C) 5
D) 12
X = (1 'K' >= 'F') ? 5 : 12Based on the code above, what is the value of x?
A) 1
B) 3
C) 5
D) 12
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 9?
A) 2
B) 4
C) 6
D) 8
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 9?
A) 2
B) 4
C) 6
D) 8
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
The conditional operator ?: takes ____ arguments.
A) two
B) three
C) four
D) five
A) two
B) three
C) four
D) five
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
switch (lastInitial)
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'E'?
A) section 2
B) section 3
C) section 4
D) section 5
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'E'?
A) section 2
B) section 3
C) section 4
D) section 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
Suppose that you have the following code:int sum = 0;
Int num = 8;if (num 5)
Sum = num + 15;After this code executes, what is the value of sum?
A) 0
B) 8
C) 15
D) 23
Int num = 8;if (num 5)
Sum = num + 15;After this code executes, what is the value of sum?
A) 0
B) 8
C) 15
D) 23
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 5?
A) 2
B) 4
C) 6
D) 8
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 5?
A) 2
B) 4
C) 6
D) 8
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
switch (lastInitial)
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'C'?
A) section 1
B) section 2
C) section 3
D) section 5
{
Case 'A':
System.out.println("section 1");
Break;
Case 'B':
System.out.println("section 2");
Break;
Case 'C':
System.out.println("section 3");
Break;
Case 'D':
System.out.println("section 4");
Break;
Default:
System.out.println("section 5");
}Based on the code above, what is the output if lastInitial = 'C'?
A) section 1
B) section 2
C) section 3
D) section 5
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
If str1 is "Hello" and str2 is "Hi", which of the following could not be a result of str1.compareTo(str2);?
A) -9
B) -5
C) -1
D) 1
A) -9
B) -5
C) -1
D) 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
int x, y;if (x 4)
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 1?
A) 2
B) 4
C) 6
D) 8
{
If (x > 7)
Y = 4;
Else
Y = 6;
}
Else
Y = 8;Based on the code above, what is the value of y if x = 1?
A) 2
B) 4
C) 6
D) 8
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
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
B) 5
C) 6
D) 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
B) 5
C) 6
D) 57
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck