Font size
S
M
L
XL
WorksheetsCOMPUTER PROGRAMMING 1 (Midterm Examination)
Total questions: 62
Worksheet time: 31hrs 0mins
Name
Class
Date
1.
Full Name (First Name, Middle Initial, Surname)
4 lines
2.
BSIT - Year & Section
a)
1A
b)
1B
c)
1C
d)
1D
e)
1E
3.
1. Who is known for leading and creating Java?
a)
Patrick Noughton
b)
Bill Gates
c)
Mark Zuckerberg
d)
James Gosling
4.
2. What is Java?
a)
A type of database
b)
An operating system
c)
A high-level programming language and environment
d)
A type of hardware
5.
3. Which of the following is NOT a use of Java?
a)
Mobile applications
b)
Web applications
c)
Operating system development
d)
Database connection
6.
4. What is the intermediate form called that the compiler translates the source code into?
a)
Source code
b)
Assembly code
c)
Machine code
d)
Bytecode
7.
5. What is type casting in Java?
a)
Converting one data type to another
b)
Declaring a variable
c)
Compiling the program
d)
Importing a package
8.
6. Which of the following statements is true about the nextLine() method of the Scanner class?
a)
It reads a line of text
b)
It reads a single character
c)
It reads a boolean value
d)
It reads an integer value
9.
7. Which method in the Scanner class is used to read an integer value from the user?
a)
nextChar()
b)
nextString()
c)
nextLine()
d)
nextInt()
10.
8. Which of the following is an arithmetic operator in Java?
a)
==
b)
&&
c)
+
d)
!
11.
9. Which of the following is an example of narrowing conversion in Java?
a)
int to long
b)
float to double
c)
double to int
d)
char to short
12.
10. What is the correct syntax for a simple if statement in Java?
a)
if (condition) { // code }
b)
if (condition): // code
c)
if condition { // code }
d)
if condition: // code
13.
11. Which loop in Java is guaranteed to execute at least once?
a)
while
b)
for
c)
foreach
d)
do-while
14.
12. In a for loop, which part is executed only once at the beginning?
a)
Body of the loop
b)
Condition
c)
Increment/Decrement
d)
Initialization
15.
13. Which keyword is used to start a conditional statement in Java?
a)
if
b)
loop
c)
case
d)
when
16.
14. Which of the following is used to test multiple conditions where only one block executes in Java?
a)
if
b)
switch-case
c)
nested if
d)
while
17.
15. What is the purpose of the break statement in a switch-case or loop?
a)
To skip the next iteration
b)
To start a new loop
c)
To declare a variable
d)
To exit the current loop or switch-case block
18.
16. What is the correct way to declare a String variable in Java?
a)
String name = "John";
b)
string name = 'John';
c)
char name = "John";
d)
String name = 'John';
19.
17. What is the correct output of this Java program?
String a = "Yes";
a = "NO";
System.out.print(a);
a)
NO
b)
Error: Unable to assign a new value
c)
Yes
d)
"Yes"
20.
18. What will be the output of the following code?
int myInt = 9;
double myDouble = myInt;
System.out.print(myInt+”, ”);
System.out.print(myDouble);
a)
9, 9.78
b)
9.0, 9.0
c)
9, 9.0
d)
9.0, 9.78
21.
19. Which of the following correctly declares and initializes an integer variable in Java?
a)
int x: 10;
b)
int x == 10;
c)
int x = 10;
d)
declare int x = 10;
22.
20. Which symbol is used to end a statement in Java?
a)
: (colon)
b)
. (period)
c)
, (comma)
d)
; (semi-colon)
23.
21. What will be the output of the following code?
int x = 5;
x++;
System.out.println(x);
a)
2
b)
7
c)
6
d)
5
24.
22. What is the correct output?
String name = "Juan";
String last = "Doe";
System.out.print(name + last);
a)
Juan+Doe
b)
JuanDoe
c)
DoeJuan
d)
Juan Doe
25.
23. What is the correct declaration of the double data type?
a)
double d = 10.2d;
b)
double c= 10;
c)
double a = '10.2';
d)
double b= "10.2";
26.
24. What is the correct way to create a Scanner object to accept input from the console?
a)
Scanner input = new Scanner(System.out);
b)
Scanner input = new Scanner(System.in);
c)
Scanner input = new Scanner(System.read);
d)
Scanner input = new Scanner(System.console);
27.
25. Which of the following is an example of widening conversion in Java?
a)
char to short
b)
byte to int
c)
int to byte
d)
double to int
28.
26. What will be the output of the following code?
double myDouble = 9.78d;
int myInt = (int) myDouble;
System.out.println(myDouble + “, “);
System.out.println(myInt);
a)
9.78, 9
b)
9, 9
c)
9.78, 9.78
d)
9, 9.78
29.
27. Analyze the following code. What type of conversion is taking place?
int myInt = 100;
long myLong = myInt;
a)
Narrowing conversion
b)
Boolean conversion
c)
String conversion
d)
Widening conversion
30.
28. What is the type of conversion here? (short to int)
a)
Narrowing conversion
b)
Boolean conversion
c)
Widening conversion
d)
String conversion
31.
29. What will be the output of the following code?
long myLong = 1000L;
int myInt = (int) myLong;
System.out.println(myInt);
a)
1000
b)
Error: incompatible types
c)
Compilation error
d)
0
32.
30. Analyze the syntax of the following code. What will be the output?
int a = 10;
int b = 20;
boolean result = (a < b) || (a > b);
System.out.println(result);
a)
true
b)
0
c)
1
d)
false
33.
31. What operator do we use in the following output statement?
int a = 0;
int b = 0;
System.out.println(a == b);
a)
Arithmetic Operator
b)
Relational/Comparison Operator
c)
Assignment Operator
d)
Logical Operator
34.
32. Which one is the symbol for AND operator?
a)
%
b)
&&
c)
||
d)
!
35.
33. What would be the boolean result of this code?
boolean isEmployed = true;
System.out.println(isEmployed);
a)
true
b)
no
c)
false
d)
yes
36.
34. What symbol do we use for NOT logical operator?
a)
||
b)
!()
c)
==
d)
&&
37.
35. Which of the following is the correct syntax for an if-else statement in Java?
a)
if (condition) { //code } else { // code }
b)
if (condition) //code else // code
c)
if (condition) { //code } else // code
d)
if condition { //code } else { // code }
38.
36. Which of the following is a correct switch statement syntax in Java?
a)
switch (variable) {value: // code break; default: // code }
b)
switch variable {case value: // code break; default: // code }
c)
switch (variable) {case value: // code break; default: // code }
d)
switch variable {value: // code break; default: // code }
39.
37. Which of the following is the correct syntax for an if statement in Java?
a)
if (code) {// condition }
b)
if condition {//code } else { // code }
c)
if (condition) {//code }
d)
if (condition): {//code }
40.
38. What will be the output of the following code?
int x = 10;
if (x > 5) {
System.out.println("x is greater than 5");
} else {
System.out.println("x is less than or equal to 5");
}
a)
x is less than or equal to 5
b)
Error
c)
x is greater than 5
d)
No output
41.
39. Give the output of the following code:
int age = 20;
System.out.println(age);
a)
You are not an adult
b)
An adult you are
c)
Error
d)
20
42.
40. The statement i++; is equivalent to?
a)
i = i + i;
b)
i = i – i;
c)
i = i - 1;
d)
i = i + 1;
43.
41. Which looping process is best used when the number of iteration is known?
a)
while loop
b)
for loop
c)
do-while loop
d)
infinite loop
44.
42. Which of the following Java programs prints “Hello, World!” correctly?
a)
public static void main(String[] args) { System.out.println("Hello, World"); }
b)
public static void main(String[] args) { System.out.println("Hello, World!"); }
c)
public static void main(String[] args) { System.out.println("Hello World"); }
d)
public static void main(String[] args) { System.out.println("Hello World!"); }
45.
43. Identify the correct naming convention in declaring an integer variable.
a)
int 1num = 10;
b)
int num1 = 10;
c)
int Num-1 = 10;
d)
int num1 = "10";
46.
44. Which Java program part is represented by: public static void main(String[] args) {}?
a)
Method Call
b)
Main Method/Method
c)
Argument
d)
Class
47.
45. Choose the correct architecture of a Java program.
a)
Source code → Bytecode → Compiler → Operating System → JVM
b)
Source code → Compiler → Bytecode → Operating System → JVM
c)
Source code → Operating System → Bytecode → Compiler → JVM
d)
Source code → Compiler → Bytecode → JVM → Operating System
48.
46. Which of the following Java programs evaluate as true?
a)
boolean a = false; System.out.println(a);
b)
String a = true; System.out.println(a);
c)
String a = false; System.out.println(a);
d)
boolean a = true; System.out.println(a);
49.
47. Which of the following Java programs evaluate as false?
a)
boolean a = true; System.out.println(a);
b)
boolean a = false; System.out.println(a);
c)
String a = true; System.out.println(a);
d)
String a = false; System.out.println(a);
50.
48. What will be the output of the following code?
int height = 140;
System.out.println(height);
a)
140
b)
14.0
c)
"140"
d)
0
51.
49. Given the variable age is an integer with initial value 20, and it should increment by 1. Which program is correct?
a)
int age = 20; System.out.println(age);
b)
String age = "20"; age++; System.out.println(age);
c)
int num = 20; System.out.println(num);
d)
int age = 20; age++; System.out.println(age);
52.
50. What will be the output of the following code?
int a = 5;
int b = 2;
System.out.println(a % b);
a)
0
b)
1
c)
2
d)
5
53.
51. Which operator is used for string concatenation in Java?
a)
+
b)
&
c)
&&
d)
||
54.
52. What will be the output of this code?
int x = 10;
x += 5;
System.out.println(x);
a)
5
b)
10
c)
15
d)
105
55.
53. Which of the following statements is correct regarding the Scanner class?
a)
nextLine() reads only one word
b)
nextInt() reads a single line
c)
nextLine() reads the entire line
d)
nextBoolean() reads a character
56.
54. Which of the following are examples of control flow statements in Java?
a)
Variables, Constants, and Data Types
b)
If Statements, Switch Statement, and Loops
c)
Classes, Objects, and Methods
d)
Packages, Interfaces, and Imports
57.
55. What will be the output of this code?
int age = 18;
if (age > 18) {
System.out.println("You are eligible to vote");
} else {
System.out.println("You are not eligible to vote");
}
a)
False
b)
True
c)
You are eligible to vote
d)
You are not eligible to vote
58.
56. Evaluate the output of the following code:
boolean c = true;
if (c) {
System.out.println("You can unlock the next level.");
}
a)
True
b)
False
c)
You can unlock the next level.
d)
ERROR
59.
57. Evaluate the output using a for loop:
for (int x = 1; x <= 5; x++) {
System.out.print("Number: " + x + " ");
}
a)
Number: 1 2 3 4 5
b)
1 2 3 4 5
c)
Number: 1 Number: 2 Number: 3 Number: 4 Number: 5
d)
ERROR
60.
58. What will the following while loop print?
int b = 1;
while (b < 4) {
System.out.print(b + " ");
b++;
}
a)
Infinite B
b)
1234
c)
1 2 3
d)
Syntax Error
61.
59. Which loop should you use when the number of iterations is unknown?
a)
for loop
b)
while loop
c)
do-while loop
d)
infinite loop
62.
60. Which loop executes at least once regardless of the condition?
a)
while
b)
for
c)
do-while
d)
foreach
Reset
