wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Practice

Total questions: 35

Worksheet time: 40mins

Name
Class
Date
1.

Which of the following lines correctly defines a String variable?

a)

String name = Sherry;

b)

String team = "Tigers";

c)

first = "money";

d)

string s = "aplus";

2.

What is the output by the code on the left?

a)

none

b)

age = 24

c)

24

d)

age

3.

Which of the following lines correctly defines a double variable?

a)

double gpa = 3.8;

b)

double = 9.1

c)

double weight = 35.1;

d)

time = 6.23

4.

What is the output by the code?

a)

"Hello " 24

b)

Hello + n

c)

Hello n

d)

Hello 24

5.

Which of the following lines correctly defines an integer variable?

a)

integer amount = 45;

b)

int age = 18

c)

int num = 16;

d)

integer = 92;

6.

What is the output by the code?

a)

Enter a word

Word = Lunch

b)

Word = word

c)

Lunch = Lunch

d)

"Word = " + word

7.

What is the output by the code?

a)

My friend has

a new car

b)

My friend

has a new car.

c)

My friend

has a

new car.

d)

My friend has

a

new car.

8.

What is the output by the code?

a)

last man standing

b)

Last man

standing

c)

Last

man

standing

d)

Last man standing

9.

What is the output by the code?

a)

Last man standing

b)

no output, compile time error

c)

Last

man

standing

d)

Last standing

10.

What is the output by the code?

a)

4

b)

4.0

c)

y

d)

error

11.

What is the output by the code?

a)

Price: $9.42

b)

Price: 9.42

c)

price

$9.42

d)

Price: $ + cost

12.

Fill in the missing code

4 lines
13.

Fill in the missing code.

4 lines
14.

(a)   is the Scanner method used to input a one word String.

15.

What will the code below draw?

window.fillOval(xPos, yPos, width, height);

a)

filled in oval

b)

outline of a rectangle

c)

filled in square

d)

outline of an oval

16.

What will the code draw?

window.fillRect(xPos, yPos, 90, 50);

a)

outline of a rectangle

b)

outline of a square

c)

filled in square

d)

filled in rectangle

17.

What is the output?

a)

10

b)

candy

c)

word

d)

Candy

18.

What is the output?

a)

Candy

b)

10

c)

0

d)

num1

19.

What is the output?

a)

84.38

b)

10

c)

num1 + 10

d)

20

20.

What is the output?

a)

10

b)

87.38

c)

average + 3

d)

84.38 + 3

21.

What is the output?

a)

word + 10

b)

Candy + 10

c)

Candy10

d)

word + num1

22.

What is the output?

a)

5

b)

num2

c)

error

d)

0

23.

What is the output?

a)

2

b)

2.5

c)

error

d)

35

24.

What is the output?

a)

0

b)

num1

c)

10

d)

11

25.
a)

num1

b)

10

c)

18

d)

8

26.

What is the output?

a)

CandyCandyCandy

b)

Candy

c)

error

d)

Candy+Candy+Candy

27.

What is the output?

a)

6Candy0

b)

6Candy21

c)

10Candy21

d)

10Candy0

28.

What is the Scanner method used to input an integer

a)

next( )

b)

NextInt( )

c)

nextInt( )

d)

nextInteger( )

29.

What is the import needed to use Scanner

a)

import java.util.Scanner

b)

Scanner

c)

import java.util.Scanner

d)

import java.util.Scanner;

30.

What is the output?

a)

error

b)

8

c)

10

d)

0.8

31.

What is the output?

a)

0

b)

15

c)

3

d)

5

32.

What is the output?

a)

12

b)

5

c)

2

d)

2.4

33.

What is the output?

a)

7

b)

0

34.

What is the output?

a)

3

b)

error

c)

2.2

d)

2

35.

What is the output?

a)

3

b)

3.33

c)

3.0

d)

3.4