wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Data Types and Operators

Total questions: 26

Worksheet time: 19mins

Name
Class
Date
1.

What will the following code print to the screen

char data = 65;

System.out.println(data);

a)

A

b)

B

c)

C

d)

D

2.

What will the following code print to the screen

char data = 76;

System.out.println(data);

a)

L

b)

M

c)

N

d)

O

3.

What will the following code print to the screen

char data = 90;

System.out.println(data);

a)

W

b)

X

c)

Y

d)

Z

4.

What will the following code print to the screen

char data = 73;

System.out.println(data);

a)

H

b)

J

c)

K

d)

I

5.

What will the following code print to the screen

char data = 84;

System.out.println(data);

a)

S

b)

T

c)

U

d)

V

6.

What will the following code print to the screen

long data = 84.0;

System.out.println(data);

a)

84

b)

84.0

c)

T

7.

What will the following code print to the screen

int data = 84.0;

System.out.println(data);

a)

84

b)

84.0

c)

T

8.

What will the following code print to the screen

byte data = 84.0;

System.out.println(data);

a)

84

b)

84.0

c)

T

9.

What will the following code print to the screen

short data = 84.0;

System.out.println(data);

a)

84

b)

84.0

c)

T

10.

What will the following code print to the screen

float data = 84.0;

System.out.println(data);

a)

84

b)

84.0

c)

T

11.

What will the following code print to the screen

double data = 84.0;

System.out.println(data);

a)

84

b)

84.0

c)

T

12.

What would be the appropriate datatype(s) to replace <var>

<var> data = 306;

System.out.println(data);

a)

byte

b)

short

c)

int

d)

long

e)

float

13.

What would be the appropriate datatype(s) to replace <var>

<var> data = 16;

System.out.println(data);

a)

byte

b)

short

c)

int

d)

long

e)

float

14.

What would be the appropriate datatype(s) to replace <var>

<var> data = 3126154587;

System.out.println(data);

a)

byte

b)

short

c)

int

d)

long

e)

float

15.

What would be the appropriate datatype(s) to replace <var>

<var> data = 3.1415926535;

System.out.println(data);

a)

float

b)

double

c)

byte

d)

int

e)

long

16.

What would be the appropriate datatype(s) to replace <var>

<var> data = 3.141593;

System.out.println(data);

a)

float

b)

double

c)

byte

d)

int

e)

long

17.

What is the answer to the following program?

public static void main (String[] args)

{

double pi = Math.Pi; //3.141593

System.out.format("pi is %.3f%n", pi);

}

a)

Pi is 3.141593

b)

Pi is 3.142

c)

Pi is 3.14

d)

Pi is 3.1

18.

What is the answer to the following program?

public static void main (String[] args)

{

double pi = Math.Pi; //3.141593

System.out.format("pi is %.0f%n", pi);

}

a)

Pi is 3.141593

b)

Pi is 0003.141593

c)

Pi is 3

d)

Pi is 3.0

19.

class MyClass

{

public static void main(String s[])

{

int i = 4;

int j = 21;


int k = ++i * 7 + 2 - j--;


System.out.println("k = " + k);

}

}

a)

k = 16

b)

Error

c)

k = 11

d)

k = 17

20.
a)

a = 2

b = 3 c = 4

d = 1

b)

a = 2

b = 3

c = 4

d = 1

c)

error

d)

a = 1

b = 2

c = 4

d = 2

21.

a)

0

b)

1

c)

2

d)

5

e)

Error

22.

Which is first incremented and then used?

a)

++x

b)

x++

c)

x+

d)

+x

23.
a)

k = 4

b)

Error

c)

k = 6

d)

k = 0

24.

What would be the value of c?


int a = 5;

int b = 3;

int c = a * b++;

int d = a * ++b;

a)

10

b)

15

c)

20

d)

25

25.

What would be the value of d?


int a = 5;

int b = 3;

int c = a * b++;

int d = a * ++b;

a)

10

b)

15

c)

20

d)

25

26.

int i = 11;

i = i++ + ++i;

System.out.println(i);

a)

22

b)

23

c)

24

d)

25