Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

UNIVERSIDAD DE ZAMBOANGA

MIDTERM Examination
Comp 2 – Computer Programming 2

NAME: _____________________________________ SCORE: ___________________


PROGRAM & YEAR LEVEL: _____________________ DATE: ____________________

GENERAL DIRECTIONS: Please read ALL the instructions carefully before you start answering. Any
erasure/alteration on your answer is considered wrong.

TEST I. MULTIPLE CHOICE


Directions: Read each statement carefully. Encircle the letter of the correct answer. (1 point each)

1. The simplest assignment operator is the standard _____ sign operator.


a. plus (add) c. multiply
b. minus (subtract) d. equal
2. Which of the following statement about Scanner class is not true?
a. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches
whitespace.
b. A Scanner is safe for multithreaded use without external synchronization.
c. A scanning operation may block waiting for input.
d. A program that does not accepts input may still run even a java.util.Scanner class is called.
3. Which of the following is a character data type?
a. ‘a’ c. 1
b. ‘num’ d. b
4. Which of the following is a result when a Java expression in a program is executed?
a. a variable c. nothing due to the expression is void
b. value d. all of the above
5. In the code snippet given below (on the right side), which of the following is the correct output?

a. “y is + false” c. y is false
b. “y is” + false d. “y is false”

6. Based on the declaration given below, if a number = 5 was entered, the entered number will be save in
_____.

a. sc c. i
b. sc.nextInt d. Scanner sc
7. ____ are Java tokens that do not change or are constant.
a. Literals c. Data Types
b. Keywords d. None of choices
8. It represents a data type that contains multiple characters.
a. Unicode character c. Floating point
b. String d. Boolean
9. Which of the following is not a Java keyword?
a. input c. Boolean
b. default d. new
10. What character is used to print single or double quotes?
a. / c. \
b. “ ” d. ‘ ‘

TEST II. IDENTIFICATION


Directions: Write the correct answer in the space provided. (1 point each)

__________________ 1. A data type that represents only two states, either true or false.

__________________ 2. By literal we mean any number, text, or other information that represents
a _____.
__________________ 3. This method finds and returns the next complete token from this scanner.

__________________ 4. This operator assigns the value of the expression on the right side to the
variable on the left side.
__________________ 5. The symbol that represents remainder operator.

__________________ 6. A simple text scanner which can parse primitive types and strings using
regular expressions.
__________________ 7. If int i = 10, int j = 3, int k = 0, evaluating k = ++j + i, will give a result of k is
equal to _____.
__________________ 8. A floating point data type that has a size of 32 bits.

__________________ 9. The symbol ++ is called _____.

__________________ 10. The size of the char data type.

TEST III. PROGRAM CODE EVALUATION


Directions: Read and review the given program codes carefully. If the program codes have errors, encircle
the errors. If there are no errors, write the program output on the right side of the given program
codes. (5 points each)

1.
package program1;

public class program1 {

public static void main(String[] args) {

int x = 0;
do {
System.out.print(x + "\n");
x++;
} while (x<=10);
}
}

2.
package program2;

public class program2 {


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

int x = 0;
while (x<10) {
System.out.printf(“x” + "\n");
x++;
}
}
}

TEST IV. PERFORMANCE TEST - LAB EXAMINATION


Directions: Perform the following by creating its required program. Save your work on this path in your
computer [C:\Users\User\Desktop\JAVA_lastname\MIDTERM_EXAM)]. (15 points each)

1. Create a program that accepts four grades for each term (Pre-mid, Midterm, Pre-final, Final) and
computes the average of the given grades. The average will be evaluated according to the following
ranges given below:
Above 90 = Congratulations! Excellent Job!
86 – 90 = Good Job! You can do better the next time.
81 – 85 = Fair Enough! You can do better the next time.
75 – 80 = Study harder to have better grades next time.
Below 75 = I’m very sorry but you failed.

Sample Output: (NOTE: The bold and underlined data are results of concatenation. Use only float data
type)

**************************************************************************************
Enter Pre-mid Grade: 92
Enter Midterm Grade: 92
Enter Pre-final Grade: 92
Enter Final Grade: 92
**************************************************************************************
Your final average is 92. Congratulations! Excellent Job!
**************************************************************************************

2. Make a program that will display the words “Last Name” if you enter your last name and displays “First
Name” if you enter your first name.

Sample Output:

Enter name: Richel


+++++++++++++++++++++
First Name
+++++++++++++++++++++

3. Make a program that will display the even numbers from 1 – 20 in a column form with this output.

######
# 2 #
# 4 #
# 6 #
# 8 #
# 10 #
# 12 #
# 14 #
# 16 #
# 18 #
# 20 #
######

Prepared by: Reviewed by: Approved by:

DELIA RUXANNA B. ISMAEL DELIA RUXANNA B. ISMAEL EDNALYN F. REYES, Ph.D.


Faculty, BSIT Program Chair, BSIT SEICT, OIC Dean

You might also like