wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Increment & Decrement Operators

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

2.

--; decreases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

3.

PRE-increment us used when you want to use the incremented

value of the variable in that expression. Whereas POST-increment uses the original value before incrementing it

a)

True

b)

False

4.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

5.

What would the new value of A be?

A=1;

A--;

a)

0

b)

1

c)

2

d)

-1

6.

What's the value of below?


int i=5;

System.out.println(i++);

System.out.println(i);

System.out.println(++i);

a)

5

6

7

b)

6

6

7

c)

6

7

8

d)

5

5

6

7.

++i and i++ cannot be used anywhere for the same purpose

a)

true

b)

false

8.

What does the following code output?

int x = 1;

System.out.println(x++);

a)

1

b)

2

c)

compilation error

d)

runtime error

9.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

10.
Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
a)
if (x > 0)  x++;
else x--;
b)
if (x > 0) x++;
else if (x < 0) x--;
c)
if (x > 0) x++;
if (x < 0) x--;
else x = 0;
d)
if (x == 0) x = 0;
else x++;
x--;