Professional Documents
Culture Documents
COLEGIO DE DAGUPAN
MIDTERM EXAMINATION
ITC02 – PROGRAMMING 1 (SET 1)
True/False
Write T if the statement is true and write F if otherwise. Write your answer in UPPERCASE form only.
____ 4. A computer program will recognize both = and == as the equality operator.
____ 6. The expression !(x > 10) is equivalent to the expression x < 10.
____ 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.
grade = "pass";
else
grade = "fail";
If score is equal to 75, the value of grade is pass.
____ 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
____ 25. Suppose x is 5 and y is 7. What is the value of the following expression?
(x != 7) && (x <= y)
|3
____ 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)
____ 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
}
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
____ 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
____ 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
____ 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
CP1-MidEx
Answer Section