Sample Midterm Exam
Sample Midterm Exam
Sample Midterm Exam
Good Luck!!
2) Which package would you import if you needed to use the Scanner
class in your Java program? [1]
java.util
3) What is one way to tell the difference between a class type and a
primitive type just by looking at the name of the type? [2]
Class types start with capital letters and primitive types start with lower
case letters
4) Write a Boolean expression that is true only when the variable x is
between 0 and 10. Please note that your expression should be true
when x equals 0, and false when x equals 10. [2]
(x >=0) && (x < 10)
5) True or false: the = operator can be used in a Boolean expression to
test whether or not two values are equal. [1] false
6) True or false: the String class part of the java.lang package can be
used without an explicit import declaration. [1] True
7) True or false: a Java program can have two different variables with the
names aVariable and avariable. [1] True
8) True or false: every variable in Java must be declared and then given a
value before it is used. [1] True
false
8.5
1
1.25
67
HiThere
false
true
4.2
8.0
4.0
title.charAt(2); [2]
0
1
2
3
4
count after loop= 5
0
0
1
0
1
2
Sum = 18
y = 10
y=9
y=8
a = 11 b = 11
value = 12
L
g