Arithmetic Operators QuizJ8 Home « Arithmetic Operators Quiz

Fundamentals Quiz 6

The quiz below tests your knowledge of the material learnt in Fundamentals - Lesson 7 - Arithmetic Operators.

Question 1 : What values do a and b hold after the following expressions?

int a = 5; int b = 10; b = a++;
- a = 6 and b = 5 as the the postfix increment is applied after the expression is evaluated.
Question 2 : What value does b hold after the following expressions?

int b = 5; b = b % 2;?
- The % symbol is the modulus and as such holds the remainder of a divisional computation and so <code>b</code> holds the value <code>1</code> after the expressions <code>int b = 5; b = b % 2;</code> are evaluated.
Question 3 : What value does b hold after the following expressions?

int b = 7; b = 22 / b;
- When division is used with an integer type, any remainder will be truncated and so <code>c</code> holds the value <code>3</code> after the expressions <code>int b = 7; b = 22 / b;</code> are evaluated..
Question 4 : Can the result of a modulus calculation be 0?
- If there is no remainder the result of a modulus calculation will be <code>0</code>.
Question 5 : What value does b hold after the following expressions?

byte a = 1;byte b = ++a;
- The prefix increment is applied before the expression is evaluated so after this <code>a = 2</code> and so the answer is <code>2</code>.
Question 6 : What value does b hold after the following expressions?

byte a = 1;byte b = a++;
- The postfix increment is applied after the expression is evaluated so after this <code>a = 1</code> and so the answer is <code>1</code>.
Quiz Progress Bar Please select an answer


What's Next?

The next quiz on Java is all about relational and logical operators available in Java.