Introduction to Java Programming, Eighth Edition, Y. Daniel Liang

Chapter 2 Elementary Programming

21  -25 % 5 is _____

A. 1
B. 2
C. 3
D. 4
E. 0

22  24 % 5 is _____

A. 1
B. 2
C. 3
D. 4
E. 0

23  -24 % 5 is _____

A. -1
B. -2
C. -3
D. -4
E. 0

24  -24 % -5 is _____

A. 3
B. -3
C. 4
D. -4
E. 0

25  To add a value 1 to variable x, you write

A. 1 + x = x;
B. x += 1;
C. x := 1;
D. x = x + 1;
E. x = 1 + x;

26  To add number to sum, you write (Note: Java is case-sensitive)

A. number += sum;
B. number = sum + number;
C. sum = Number + sum;
D. sum += number;
E. sum = sum + number;

27  Suppose x is 1. What is x after x += 2?

A. 0
B. 1
C. 2
D. 3
E. 4

28  Suppose x is 1. What is x after x -= 1?

A. 0
B. 1
C. 2
D. -1
E. -2

29  What is x after the following statements?

int x = 1;
int y = 2;
x *= y + 1;


A. x is 1.
B. x is 2.
C. x is 3.
D. x is 4.

30  What is x after the following statements?

int x = 1;
x *= x + 1;


A. x is 1.
B. x is 2.
C. x is 3.
D. x is 4.