You are on page 1of 3

Republic of the Philippines

Department of Education
Region VII, Central Visayas
DIVISION OF CITY OF BOGO
CITY OF BOGO SCIENCE AND ARTS ACADEMY
St. Joseph Vill., Cogon, Bogo City, Cebu

THIRD QUARTER PERIODIC EXAM


Computer Programming

Name: _____________________________________________ Track/Sec:________________ Date:_____________ Score: _______


TEST I. MULTIPLE CHOICE. Encircle the letter of the correct answer. Erasure means WRONG.
1. Who is the creator of Java Programming language?
a. Tim Berners-Lee c. Allan Turing
b. James Gosling d. Rasmus Lerdorf
2. What Java function is used to display an output?
a. System.out.print() c. public static void main()
b. System.in d. print()
3. What symbol is used to concatenate Strings in Java?
a. + c. /
b. . d. “
4. Which of the following is a valid Java variable name?
a. 4ever c. variable name
b. du30 d. var@scan
5. Which of the following statements is not true about Java Identifiers or variables?
a. A keyword cannot be used as an identifier.
b. After the first character, identifiers can have any combination of characters.
c. An identifier cannot start with a number.
d. Identifiers are not case sensitive.
6. What class is imported from java.util that enables our program to read inputs from the user.
a. Import c. Scanner
b. Class d. Read
7. What data type is “3.14”?
a. Integer c. Float
b. String d. Double
8. Which of the following is not a Java data type?
a. short c. char
b. long d. bit
9. Which of these is incorrect string literal?
a) “Hello World” c) “\”Hello World\””
b) “Hello\nWorld” d) “Hello
world”
10. With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
a) 1, 2 & 3 c) 1, 2, 3 & 4
b) 1 & 4 d) 3 & 2
11. Decrement operator, −−, decreases value of variable by what number?
a) 1 c) 3
b) 2 d) 4
12. What is the output of relational operators?
a) Integer c) Characters
b) Boolean d) Double
13.Which of these is returned by “greater than”, “less than” and “equal to” operators?
a) Integers c) Boolean
b) Floating – point numbers d) None of the mentioned
14. What is the answer of 20%6?
a. 1 c. 3.3
b. 0 d. 2
15. What is the value stored in x in the following lines of code?
int x, y, z;
x = 0;
y = 1;
y = y * 6 + 2;
a) 0 c) 9
b) 1 d) 8
TEST II. TRUE OR FALSE. Evaluate the following conditional expressions:
16.) (9>3) || (3==0) && (5>=5) || (8<=3)

17.) (4<5) && (6>3) || (7<4) && (5!=6)

18.) (6<=3) && (4!=4) || (1>=0) && (5<=-5) || (8!=8)

19.) (9>=6) || (3>8) && (4!=4) || (2<=5)

20.) (-1!=1) && (6<9) && (4>=-7)

TEST III. OUTPUT TRACING. Generate the output of the following code.

21.) public static void main(String args[]){


int m = 9;
int n = 6;

n = n-- - --n;
System.out.print(‘n’);
System.out.print(m--);
}
22.) public static void main(String args[]){
int v = 10;
int w = v;

v = v + --w;
w = w * 0;
System.out.print(v);
System.out.println(w);
}
23.) public static void main(String args[]){
int y = 2, v = 5;

System.out.println(“v * y”);
System.out.printf(v + “ ” + (v%y));
}
24.) public static void main(String args[]){
int i = 6, j = 9;

j = 0;
i = i-- + j – i;
System.out.println(i);
}
25.) public static void main(String args[]){
int n = 8, u = 3;

n = n-- % n;
u = --u * u;
System.out.print(u++);
System.out.print(n++);
}
TEST IV. FINDING THE ERROR. The following Java Program is riddled with errors. Encircle all the errors you can find. Be
specific as possible as you can. The highest possible score is 20/15. Right minus Wrong.

/*
A local pizza house is offering a discount-treat to its customers according to their age:
MINORS - 10%, SENIOR CITIZEN - 5%
The regular prize of a pizza is P350.00.
Create a java program that accepts an age of the customer and outputs the discounted
amount of pizza the customer should pay.
*/

Import java.util.scanner;

class PizzaDiscountIfElse{

Public static void main(String args[]){;

int age = 0
double discountedAmount = 0.0;
Scanner ageScanner = new Scanner(system.in);

System.out.println("HELLO!!!\nAvail our special treat NOW! );


System.out.println("Minors - 5%\nSenior Citizen - 10%");
System.out.print("\nEnter age --> ");
age = age.nextInt()

If(age < 18){


discountedAmount = 350 - (350 * 0.1);
}
else If(age > 65){
discountedAmount = 320 - (350 * 0.5);
}
else{
discountedAmount = 350.00;
}
System.out.println("\nYou should pay ---> P" + discounted);
system.out.println("\nTHANK YOU");

This is the sample output:

TEST V. CODING: Create a Java Program for the following problem / situation. Write your answer at the back.

Write a Java program that accepts two numbers from the user and checks if the first number is a factor of the
second number. Refer to the sample output below.

You might also like