wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Arithmetic Types Declare Initialize Relation Logical Ops

Total questions: 16

Worksheet time: 1hrs 20mins

Name
Class
Date
1.

Which Java type(s) can hold decimals? (Choose all that apply)

a)

int

b)

float

c)

double

d)

String

2.

34 % 35 % 36 % 37 % 38

a)

0.00001919212

b)

38

c)

34

d)

Impossible

3.

What does the following code print?

System.out.println(1 / 3);

a)

0.3333333333333333

b)

0

c)

an error

d)

0.3

4.

What will the following code print?

system.out.println(2.0 / 9);

a)

0.222222222222222 (14 - 15 significant digits)

b)

0

c)

error

5.

Consider the following code segment.


System.out.print("Java is");

System.out.println("fun ");

System.out.print("and cool!");


What is printed as a result of executing the code segment?

a)

Java is fun and cool!

b)

Java isfun

and cool!

c)

Java is

fun

and cool!

d)

Java is fun

and cool!

6.

Which of the following correctly assigns a value to the variable x?

a)

x int = 5;

b)

int x;

c)

x = 5;

d)

int x

e)

x = 5

7.

Which of the following correctly declares a variable x of type int?

a)

x int = 5;

b)

int x;

c)

x = 5;

d)

int x

e)

x = 5

8.

Consider the following code segment.

// Geez, textbooks are expensive!

double bookPrice = 79.4; // Line 1

int numBooks = 5; // Line 2

System.out.println(bookPrice); // Line 3

System.out.println(numBooks); // Line 4


// Prices dropped, so I bought more!

bookPrice = 56; // Line 5

numBooks = 8.5; // Line 6

System.out.println(bookprice); // Line 7

System.out.println(numBooks); // Line 8


Does this code contain any syntax errors? If so, on which line(s)?

Select ALL that apply!

a)

Line 5 contains an error.

b)

Line 6 contains an error.

c)

Line 7 contains an error.

d)

Line 8 contains an error.

e)

This contains no errors.

9.

Consider the following code


int x, y, z;

x = 3;

y = 7;

z = 21;

x = y;

y = z;

System.out.print(x);

System.out.print(" ");

System.out.print(y);


Which of the following will be displayed after the code is run?

a)

3 7

b)

21 21

c)

3 3

d)

7 21

10.

What value of body_temp would yield "You have hypothermia."?

a)

97

b)

96

c)

101

d)

100.4

11.

Given the following code segment, which of the following is this equivalent to?

a)
b)
c)
d)
e)
12.

What error message will be displayed when this code fragment is executed?


int x;

System.out.println(x);

a)

Incompatible type error

b)

Arithmetic error

c)

x may not have been initialized

d)

syntax error

13.

Evaluate 4 == 4 || 193775/56 >3460

a)

true

b)

false

c)

error

d)

3,460.267857142857

14.

Which expression is logically equivalent to !(x > y || y <= z) ?

a)

x < y || y >=z

b)

x < y && y >= z

c)

x <= y || y > z

d)

x <= y && y > z

15.

What error message will be displayed when this code fragment is executed?


int x = 3.14;

System.out.println(x);

a)

incompatible types error

b)

Arithmetic error

c)

x may not have been initialized

d)

syntax error

16.

Evaluate 4==5 && 193775/56 >3460

a)

true

b)

false

c)

error

d)

3,460.267857142857