Professional Documents
Culture Documents
MIDTERM - Comp 2
MIDTERM - Comp 2
MIDTERM Examination
Comp 2 – Computer Programming 2
GENERAL DIRECTIONS: Please read ALL the instructions carefully before you start answering. Any
erasure/alteration on your answer is considered wrong.
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. ‘ ‘
__________________ 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.
1.
package program1;
int x = 0;
do {
System.out.print(x + "\n");
x++;
} while (x<=10);
}
}
2.
package program2;
int x = 0;
while (x<10) {
System.out.printf(“x” + "\n");
x++;
}
}
}
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:
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 #
######