You are on page 1of 6

|1

COLEGIO DE DAGUPAN
MIDTERM EXAMINATION
ITC02 – PROGRAMMING 1 (SET 3)

Instructions: Name: _________________________________________


 Turn off your cell phone/s. Use of CP is not allowed during exam. Course, Year and Block: ____________________________
 Write ALL YOUR ANSWERS legibly on your TEST BOOKLET. Subject Code & Description: ________________________-
 Use blue or black pen only. Strictly: NO ERASURE. _______________________________________________
 READ and FOLLOW the DIRECTIONS carefully! Date: __________________________________________

True/False
Write T if the statement is true and write F if otherwise. Write your answer in UPPERCASE form only.

____ 1. A computer program will recognize both = and == as the equality operator.

____ 2. Determine whether the statement


(10 >= 5) && (7 <= 4)
is true or false.

____ 3. Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.

____ 4. A program uses repetition to implement a branch.

____ 5. The expression !(x > 10) is equivalent to the expression x < 10.

____ 6. The expression !(x < 0) is true only if x is a positive number.

____ 7. The symbol > is a logical operator.

____ 8. != is a relational operator.

____ 9. Determine whether the statement


6.9 <= 7.6
is true or false.

____ 10. Suppose x = 10 and y = 20. The value of the expression ((x >= 10) && (y <= 20)) is true.

____ 11. The output of the Java code


int x = 5;
if (x > 10)
System.out.println("Hello ");
System.out.println("There. ");
System.out.println("How are you?");
is: There. How are you?

____ 12. An else statement must be paired with an if statement.

____ 13. Suppose that the input is 5 and console is a Scanner object initialized to the standard input device. Consider
the following code.
int alpha = 3;
int beta = console.nextInt();
switch (beta)
{
case 3:
alpha = alpha + 3;
case 4:
alpha = alpha + 4;
case 5:
|2

alpha = alpha + 5;
default:
alpha = alpha + 6;
}
The output of this code is 14.

____ 14. Suppose found = true and num = 6. The value of the expression
(!found) || (num > 6)
is false.

____ 15. 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.

____ 16. The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.

____ 17. Suppose P and Q are logical expressions. The expression P || Q is false if either P is false or Q is false.

____ 18. Suppose that you have the following code.


int num = 5;
if (num >= 5)
System.out.println(num);
else
System.out.println(num + 5);
The output of this code is 10.

____ 19. You write pseudocode in everyday language, not the syntax used in a programming language.

____ 20. When you use nested if statements, you must pay careful attention to placement of any else clauses.

Multiple Choice
Choose the letter that best corresponds to your answer. Write the letter of your answer in UPPERCASE form.

For numbers 21 to 22, refer to the code fragment below:


5 < 3 || 6 < 7 || 4 > 1 && 5 > 3 || 2 < x
____ 21. Based on the code above, which of the statements is not evaluated?
a. 5 < 3 c. 2 < x
b. 6 < 7 d. 5 > 3

____ 22. What is the value of the expression above?


a. true c. x
b. false d. It cannot be determined.

____ 23. A logical structure called ____ structure is when one step follows another unconditionally.
a. straight c. sequence
b. decision d. unconditional

____ 24. The AND operator is written as two ____.


a. plus signs c. ampersands
b. equal signs d. asterisks
|3

____ 25. Which of the following is a relational operator?


a. = c. !
b. == d. &&

____ 26. In a ____ control structure, the computer executes particular statements depending on some condition(s).
a. looping c. selection
b. repetition d. sequence

____ 27. Which of the following is NOT a relational operator in Java?


a. != c. <<
b. <= d. >=

____ 28. Suppose x is 5 and y is 7. What is the value of the following expression?
(x != 7) && (x <= y)
a. false c. This is an invalid expression in Java.
b. true d. None of these

____ 29. Suppose that x is an int variable. Which of the following expression always evaluates to true?
a. (x > 0) || ( x <= 0) c. (x > 0) && ( x <= 0)
b. (x > 0) || (x == 0) d. (x > 0) && (x == 0)

____ 30. What is the output of the following code?


if (5 > 4 + 3)
System.out.println("Hello");
System.out.println("World");
a. Hello c. World
b. Hello World d. There is no output.

____ 31. Two-way selection in Java is implemented using ____.


a. if statements c. if...else statements
b. for loops d. sequential statements

____ 32. What is the output of the following Java code?


int x = 6;
if (x > 10)
System.out.println("One ");
System.out.println("Two ";
a. One c. One Two
b. Two d. None of these

____ 33. Which of the following is not a logical operator?


a. ! c. !=
b. || d. &&

____ 34. After the exeution of the following code, what will be the value of num if the input values are 4 5? (Assume that
console is a Scanner object initialized to the standard input device.)
int num = console.nextInt();
if (num > 0)
num = num + 10;
else
if (num >= 5)
num = num + 15;
a. 4 c. 14
b. 5 d. 15

For numbers 35-37, refer to the following code:


int x, y;
|4

if (x > 5)
y = 1;
else if (x < 5)
{
if (x < 3)
y = 2;
else
y = 3;
}
else
y = 4;
____ 35. Based on the code above, what is the value of y if x = 5?
a. 1 c. 3
b. 2 d. 4

____ 36. Based on the code above, what is the value of y if x = 6?


a. 1 c. 3
b. 2 d. 4

____ 37. Based on the code above, if the value of y is found to be 2, what is a possible value of x?
a. 2 c. 5
b. 3 d. 6

____ 38. Statements in which an if structure is contained inside another if structure are commonly called ____ if
statements.
a. nested c. blocked
b. logical d. inside

____ 39. What is the output of the following code?


if ( 6 > 8)
{
System.out.println(" ** ");
System.out.println("****");
}
else if (9 == 4)
System.out.println("***");
else
System.out.println("*");
a. * c. ***
b. ** d. ****

____ 40. Which of the following is not a selection control structure in Java?
a. if c. case
b. if...else d. switch

____ 41. A(n) ____ statement is the decision structure you use when you need to take one or the other of two possible
courses of action.
a. Boolean c. single-alternative if
b. dual-alternative if d. if...else

____ 42. The ____ statement is useful when you need to test a single variable against a series of exact integer or
character values.
a. switch c. else
b. if d. break

For numbers 43 to 44, refer to the subsequent code:


switch (lastInitial)
|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");
}
____ 43. Based on the code above, what is the output if lastInitial = 'A'?
a. section 1 c. section 3
b. section 2 d. section 5

____ 44. A(n) ____ consists of written steps in diagram form, as a series of shapes connected by arrows.
a. pseudocode chart c. sequence structure
b. flowchart d. decision structure

____ 45. Based on the code above, what is the output if lastInitial = 'S'?
a. section 2 c. section 4
b. section 3 d. section 5

Matching
Identify the letter that matches the following statements. Write your answer in UPPERCASE form.
a. relational operator f. pipes
b. conditional operator g. dual-alternative
c. Boolean values h. !
d. equality i. AND operator
e. switch statement j. logical operator

____ 46. true and false

____ 47. double equal sign

____ 48. > or <

____ 49. alternative to using a series of nested if statements

____ 50. Logical NOT operator


c R c S e c o |6
11112

CP1-MidEx
Answer Section

TRUE/FALSE
1. ANS: F PTS: 1 REF: 178
2. ANS: F PTS: 1 REF: 180
3. ANS: T PTS: 1 REF: 180
4. ANS: F PTS: 1 REF: 181
5. ANS: F PTS: 1 REF: 181
6. ANS: F PTS: 1 REF: 189
7. ANS: F PTS: 1 REF: 189
8. ANS: T PTS: 1 REF: 190
9. ANS: T PTS: 1 REF: 190
10. ANS: T PTS: 1 REF: 190
11. ANS: T PTS: 1 REF: 190
12. ANS: T PTS: 1 REF: 190 | 191
13. ANS: T PTS: 1 REF: 190
14. ANS: T PTS: 1 REF: 204
15. ANS: T PTS: 1 REF: 201
16. ANS: F PTS: 1 REF: 201
17. ANS: F PTS: 1 REF: 202
18. ANS: F PTS: 1 REF: 213
19. ANS: T PTS: 1 REF: 188
20. ANS: T PTS: 1 REF: 198
MULTIPLE CHOICE
21. ANS: C PTS: 1 REF: 179
22. ANS: A PTS: 1 REF: 180
23. ANS: C PTS: 1 REF: 180
24. ANS: C PTS: 1 REF: 189
25. ANS: B PTS: 1 REF: 190
26. ANS: C PTS: 1 REF: 190 | 191
27. ANS: C PTS: 1 REF: 192 | 193
28. ANS: B PTS: 1 REF: 192 | 193
29. ANS: A PTS: 1 REF: 198 | 204
30. ANS: C PTS: 1 REF: 201
31. ANS: C PTS: 1 REF: 204
32. ANS: B PTS: 1 REF: 201
33. ANS: C PTS: 1 REF: 201| 202 | 203 | 204
34. ANS: C PTS: 1 REF: 201| 202 | 203 | 204
35. ANS: D PTS: 1 REF: 201| 202 | 203 | 204
36. ANS: A PTS: 1 REF: 206
37. ANS: B PTS: 1 REF: 211 | 212
38. ANS: A PTS: 1 REF: 211 | 212
39. ANS: A PTS: 1 REF: 198 | 201 | 211
40. ANS: C PTS: 1 REF: 188
41. ANS: B PTS: 1 REF: 188
42. ANS: A PTS: 1 REF: 193
43. ANS: A PTS: 1 REF: 197
44. ANS: B PTS: 1 REF: 199
45. ANS: D PTS: 1 REF: 207
MATCHING
46. ANS: C PTS: 1 REF: 190
47. ANS: D PTS: 1 REF: 190
48. ANS: A PTS: 1 REF: 212
49. ANS: E PTS: 1 REF: 207
50. ANS: H PTS: 1 REF: 212

You might also like