You are on page 1of 6

|1

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

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 program uses repetition to implement a branch.

____ 2. The symbol > is a logical operator.

____ 3. != is a relational operator.

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

____ 5. Determine whether the statement


6.9 <= 7.6
is true or false.

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

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

____ 8. Determine whether the statement


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

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

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

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

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

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

____ 14. 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?

____ 15. Suppose that you have the following statements.


int score;
String grade;

if (score >= 65)


|2

grade = "pass";
else
grade = "fail";
If score is equal to 75, the value of grade is pass.

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

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

____ 18. 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:
alpha = alpha + 5;
default:
alpha = alpha + 6;
}
The output of this code is 14.

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

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

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


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

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


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

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


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

____ 25. Suppose x is 5 and y is 7. What is the value of the following expression?
(x != 7) && (x <= y)
|3

a. false c. This is an invalid expression in Java.


b. true d. None of these

____ 26. 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)

5 < 3 || 6 < 7 || 4 > 1 && 5 > 3 || 2 < x


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

5 < 3 || 6 < 7 || 4 > 1 && 5 > 3 || 2 < x


____ 28. What is the value of the expression above?
a. true c. x
b. false d. It cannot be determined.

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

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


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

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

____ 32. 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 33-35, refer to the following code:


int x, y;
if (x > 5)
y = 1;
else if (x < 5)
{
if (x < 3)
y = 2;
else
y = 3;
|4

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

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


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

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

____ 36. 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. ****

For numbers 37 to 38, refer to the subsequent code:


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

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

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

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

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

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

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

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


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

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

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 26. ANS: A


1. ANS: F 27. ANS: C
2. ANS: F 28. ANS: A
3. ANS: T 29. ANS: C
4. ANS: F 30. ANS: C
5. ANS: T 31. ANS: B
6. ANS: F 32. ANS: C
7. ANS: F 33. ANS: D
8. ANS: F 34. ANS: A
9. ANS: T 35. ANS: B
10. ANS: T 36. ANS: A
11. ANS: F 37. ANS: A
12. ANS: F 38. ANS: D
13. ANS: T 39. ANS: C
14. ANS: T 40. ANS: B
15. ANS: T 41. ANS: C
16. ANS: F 42. ANS: B
17. ANS: T 43. ANS: A
18. ANS: T 44. ANS: C
19. ANS: T 45. ANS: A
20. ANS: T MATCHING
MULTIPLE CHOICE 46. ANS: C
21. ANS: C 47. ANS: D
22. ANS: C 48. ANS: A
23. ANS: B 49. ANS: E
24. ANS: C 50. ANS: H
25. ANS: B

You might also like