WorksheetsJava Practice
Total questions: 35
Worksheet time: 40mins
Which of the following lines correctly defines a String variable?
String name = Sherry;
String team = "Tigers";
first = "money";
string s = "aplus";
What is the output by the code on the left?
none
age = 24
24
age
Which of the following lines correctly defines a double variable?
double gpa = 3.8;
double = 9.1
double weight = 35.1;
time = 6.23
What is the output by the code?
"Hello " 24
Hello + n
Hello n
Hello 24
Which of the following lines correctly defines an integer variable?
integer amount = 45;
int age = 18
int num = 16;
integer = 92;
What is the output by the code?
Enter a word
Word = Lunch
Word = word
Lunch = Lunch
"Word = " + word
What is the output by the code?
My friend has
a new car
My friend
has a new car.
My friend
has a
new car.
My friend has
a
new car.
What is the output by the code?
last man standing
Last man
standing
Last
man
standing
Last man standing
What is the output by the code?
Last man standing
no output, compile time error
Last
man
standing
Last standing
What is the output by the code?
4
4.0
y
error
What is the output by the code?
Price: $9.42
Price: 9.42
price
$9.42
Price: $ + cost
Fill in the missing code
Fill in the missing code.
(a) is the Scanner method used to input a one word String.
What will the code below draw?
window.fillOval(xPos, yPos, width, height);
filled in oval
outline of a rectangle
filled in square
outline of an oval
What will the code draw?
window.fillRect(xPos, yPos, 90, 50);
outline of a rectangle
outline of a square
filled in square
filled in rectangle
What is the output?
10
candy
word
Candy
What is the output?
Candy
10
0
num1
What is the output?
84.38
10
num1 + 10
20
What is the output?
10
87.38
average + 3
84.38 + 3
What is the output?
word + 10
Candy + 10
Candy10
word + num1
What is the output?
5
num2
error
0
What is the output?
2
2.5
error
35
What is the output?
0
num1
10
11
num1
10
18
8
What is the output?
CandyCandyCandy
Candy
error
Candy+Candy+Candy
What is the output?
6Candy0
6Candy21
10Candy21
10Candy0
What is the Scanner method used to input an integer
next( )
NextInt( )
nextInt( )
nextInteger( )
What is the import needed to use Scanner
import java.util.Scanner
Scanner
import java.util.Scanner
import java.util.Scanner;
What is the output?
error
8
10
0.8
What is the output?
0
15
3
5
What is the output?
12
5
2
2.4
What is the output?
7
0
What is the output?
3
error
2.2
2
What is the output?
3
3.33
3.0
3.4
