wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Math

Total questions: 15

Worksheet time: 12mins

Name
Class
Date
1.

What will the following code segment print?

System.out.println(4 / 5);

(a)  

2.

What will the following code segment print?

System.out.println(4 * 2.0);

(a)  

3.

What will the following code segment print?

System.out.println("b" + 2 * 2);

(a)  

4.

What will the following code segment print?

System.out.println(1 / 2.0);

(a)  

5.

What will be the value in variable x after this code segment is executed?

int x = 5.0 + 2;

a)

7

b)

7.0

c)

There will be a runtime error

d)

There will be a syntax error

e)

5.02

6.

What will be the value in variable x after this code segment is executed?

String x = "" + 4 + 2;

a)

"6"

b)

"6.0"

c)

There will be a runtime error

d)

There will be a syntax error

e)

"42"

7.

What will the following code segment print?

System.out.println(17 % 3);

(a)  

8.

What will the following code segment print?

System.out.println(6 % 9);

(a)  

9.

What will be the value in variable x after this code segment is executed?

double x = 5.0 + 2;

a)

7

b)

7.0

c)

There will be a runtime error

d)

There will be a syntax error

e)

5.02

10.

What will be the value in variable x after this code segment is executed?

int x = (int) 5.0 / 2;

a)

2

b)

2.5

c)

There will be a runtime error

d)

There will be a syntax error

e)

3

11.

What will be the value in variable x after this code segment is executed?

double x = (double) 5 / (int) 2

a)

2

b)

2.5

c)

There will be a runtime error

d)

There will be a syntax error

e)

2.0

12.

What will be the value in variable x after this code segment is executed?

double x = (int) (1.0 / 2)

a)

0.5

b)

0.0

c)

There will be a runtime error

d)

There will be a syntax error

e)

0

13.

What will the following statement print?

System.out.println(Math.sqrt(9));

(a)  

14.

What will be the range of possible values generated by the following statement for x?

double x = Math.random() * 8 - 5;

a)

[0,3)\left[0,3\right)

b)

[5,3)\left[-5,3\right)

c)

[5,8)\left[-5,8\right)

d)

[0,8)\left[0,8\right)

e)

[3,8)\left[3,8\right)

15.

What will the following statement print?

System.out.println(Math.pow(2,3));

(a)