WorksheetsGrade 11 Midterm
Total questions: 23
Worksheet time: 22mins
Fill in the blank: The class used for taking input in Java is called (a) .
Question: Which method is used to print output in Java?
System.out.input()
System.out.println()
System.out.read()
System.println()
Open-ended: Write a Java code snippet that takes an integer input from the user and prints it to the console.
Fill in the blank: To read a string input in Java, we use the method (a) .
Question: What does System.out.println() do in Java?
Takes input from the user.
Prints a message to the console.
Reads a file.
Terminates the program.
Question: Which of the following correctly reads an integer value from the user?
int num = input.readInt();
int num = input.nextInt();
int num = scanner.read();
Fill in the blank: To import the Scanner class, we use import ______;.
Question: What is the output of the following code? If the input is 25, what will be printed?
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println("The number is: " + num);
25
The number is: 25
The number is: num
The number is: null
Question: What will be the output of the following code?
int a = 10;
int b = 5;
System.out.println(a + b);
15
105
5
50
Fill in the blank: The operator used for division in Java is (a) .
Open-ended: Write a Java code snippet that subtracts two numbers, taken as input, and prints the result.
Question: How do you correctly subtract two numbers in Java?
num1 minus num2
num1 -- num2
num1 - num2
subtract(num1, num2)
Question: Which of the following is the correct syntax for multiplication in Java?
num1 * num2
num1 × num2
num1 multiply num2
num1 + num2
Fill in the blank: The result of the expression 12 / 5 in Java (when both are integers) is (a) .
Question: What is the output of this code?
int num = 7;
num = num + 3;
System.out.println(num);
7
3
10
73
Fill in the blank: The operator used to add two numbers in Java is (a) .
Question: What will be the output of this Java code?
int num1 = 8;
int num2 = 3;
System.out.println(num1 * num2);
24
5
11
83
Question: What is the output of this code?
int num = 20;
System.out.println(num / 4);
4.0
5
5.0
20
Question: What will this code print?
int a = 15;
a = a - 5;
System.out.println(a);
15
5
10
20
Fill in the blank: The result of 9 / 3 in Java is (a) .
Open-ended: Write a Java code snippet that multiplies two numbers, taken as input, and prints the result.
Fill in the blank: The output of int a = 12; int b = 4; System.out.println(a / b); is (a) .
Question: What does the following code do?
int a = 7;
int b = -5;
System.out.println(a - b);
Prints 7
Prints 12
Prints 2
Gives an error
