You are on page 1of 3

Name: ______________________________________ Score: ______________

Grade/Section: _______________________________
I. MULTIPLE CHOICE: Write the letter of your answer on the blank before each
number.
1. What will the output be of this expression if the variable x = 13?

If(x<12){
System.out.println(“The number was too low”);
}
a. The number was too low c. x < 12
b. x = 13 d. Nothing will happen.
2. The Java conditional if statement:
a. Evaluates whether an expression is equal or not
b. Evaluates whether an expression is true or false
c. Evaluates whether an expression is less than or more than a number
d. Evaluates whether a String object contains certain letters or not
3. A Java application should always have three things. Which of these isn't one of them?
a. The class name c. Comments
b. The main method d. A declared variable
4. An if-statement inside another if statement is called?
a. If statement c. Conditional statement
b. Nested if statement d. Else if statement
5. What is the correct syntax for the if-statement?
a. if(expression){statement) c. if(expression){statement;}
b. if(expression;){statement} d. if(expression){statement;)
6. What is the correct syntax for the if-else statement?
a. if(expression){statement;} else(statement)
b. if(expression){statement;} else(statement;)
c. if(expression){statement;} else(statement){}
d. if(expression){statement;} else{statement;}
7. What is the correct syntax for the if-else-if statement?
a. if(expression){statement;} else if(statement)
b. if(expression){statement;} else if(condition)(statement;)
c. if(expression){statement;} else(statement){}
d. if(expression){statement;} else if(condition){statement;}
8. If an if-statement is true it will execute all the statements enclosed inside the curly
braces.
a. Always true c. Never true
b. Sometimes true d. False
9. If an if-statement is false it will execute some of the statements enclosed inside the curly
braces.
a. Always true c. Never true
b. Sometimes true d. True
10. What will the output be of this expression if the variable x = 12?

If(x==12){
System.out.println(“The numbers are equal”);
}
a. The numbers are equal c. x < 12
b. x == 13 d. Nothing will happen

11. An increment operator increases the value stored in a number variable by?
a. 4 b. 1 c. 2 d. 3
12. A decrement operator decreases the value stored in a number variable by?
a. 2 b. 3 c. 4 d. 1
13. If a variable was declared as int x=7; what is the value of ++x?
a. 8 b. 6 c. 7 d. 9
14. If a variable was declared as int y=4; what is the value of --y?
a. 2 b. 1 c. 3 d. 4
15. If a variable was declared as int z=9; what is the value of z++?
a. 8 b. 9 c. 10 d. 7
16. If variable a=8 and b=7, What is (- -a)+(b- -)?
a. 15 b. 13 c. 12 d. 14
17. If a variable was declared as int d=9; what is the value of d--?
a. 7 b. 8 c. 10 d. 9
18. If variable a=2,b=8 and c=10, What is ((b++) / (a++))+((c++)*(a++))?
a. 22 b. 23 c. 24 d. 21
19. If a variable was declared as int d=0; what is the value of d--?
a. 0 b. -1 c. -2 d. 1
20. If a variable was declared as int d=0; what is the value of --d?
a. 0 b. -1 c. -2
d. 1

II. TRUE or FALSE: Based on the sample code below. Determine if the statements
given are true or false. Write your answer on the space provided for.(2 points each)

public class Sample {


public static void main(String []args){
int x=1;
while(x<=10){
int y=1;
while(y<=10){
System.out.print(x*y);
System.out.print(" ");
y++;
}
System.out.println();
x++;
}
}
}

1. The while loops will repeat exactly 10 times.


2. The variable x will have a value 11.
3. The variable y will have a value 11.
4. The outside while loop will terminate when the value of x is 10.
5. The value of y after the third repetition is 3.
6. A new line will be appended every 11th repetition.
7. A product of 30 will display on the third repetition of the inside while loop.
8. A product of 27 will display on the 9th repetition of the inside while loop.
9. The value of x is 7 on the 7th repetition of the while loop.
10. The inner while loop will display a space every 10th repetition.

III. SHORT ANSWER: Write the program statement for the following problems given.(5
points each)
1. Create an if statement to determine if a student passes or fails a subject.
2. Create an if statement to determine if a given number is greater than 10.
3. Using for loop, create a code that displays your name 5 times.
4. Using while loop, create a code that prints the number 1 to 10 in descending
order.
5. Using for loop, create a code that prints the number 1 to 10 in ascending order.

IV. PROGRAM CREATION:


1. Create a program that accepts your name. The program will display your entered
name ten times. The class name will be FinalExam.(20 points)

You might also like