Preview

06 - Compound Assignment Operators

 1. Java uses (==) to test if the value on the left is equal to the value on the right and (!=) to test if two items are not equal.

  TRUE

  FALSE

 2. ____________ assignment operators (+=, -=, *=, /=, %=) can be used in place of the assignment operator

  Compound

  Double

  Distributed

  Extreme

 3. Consider this statement: a = a+6; In Java this can also be written as:

  aa6+

  a = 6 + .

  a + a = 6 +

  a += 6;

 4. The increment operator (++) and decrement operator (--) are used to___ 1 or _____1 from the stored value of a variable or an array element.

  add / subtract

  divide by / multiply by

  delete / consume

  extract / exponent

 5. Compound operators, also called combined assignment operators, are a __________ way to update the value of a variable.

  extended

  shorthand

  mathematical

  inaccurate

 6. What does the following compound assignment operator do? -=

  Decrements then assigns

  Modulus then assigns

  Binary Right Shift and assigns

  Shift right zero fill and assigns

 7. What does the following compound assignment operator do? %=

  Binary AND assigns

  Binary Right Shift and assigns

  Decrements then assigns

  Modulus then assigns

 8. What does the following compound assignment operator do? &=

  Binary AND assigns

  Binary Right Shift and assigns

  Binary inclusive OR and assigns

  Binary exclusive OR and assigns

 9. What does the following compound assignment operator do? >>=

  Binary AND assigns

  Decrements then assigns

  Modulus then assigns

  Binary Right Shift and assigns

 10. What does the following compound assignment operator do? |=

  Binary exclusive OR and assigns

  Binary inclusive OR and assigns

  Binary Right Shift and assigns

  Binary AND assigns

 11. What is the final value of i?
int i=2;       //initializing i to 2
i*=2;

  8

  2

  12

  4

 12. What is the final value of a?
int a = 2;
int b = 3;
a *= b + 1;

 13. A binary operator will always have exactly two operands. However, sometimes one or both operands of a binary operator is a subexpression.

  True

  False

 14. Name the constant that is being used in this program.
public class CalculateTax
{
  public static void main ( String[] arg )
  {
    final double DURABLE = 0.045;
    final double NONDURABLE = 0.038;

    . . . . . .
  }
}

 15. Which of the following is an advantage of using a constant (as has been done in the above question) in your program?

  Constants can allow for quick updating and changing (you don' t have to change each occurrence)

  Constants make your program easier to check for correctness and accuracy

  Constants make your program easier to read

  All these statements are valid advantages of the use of constants

 16. Which of the following has the highest operator precedence?

  remainder

  unary minus -

  multiplication *

  addition

 17. Which of the following has the highest operator precedence?

  short addition +

  addition

  multiplication *

  subtraction

 18. The Modulus operator is often used, as is the case in this example, to ________________________________.
(num % 2 == 1 is odd and num % 2 == 0 is even). 

  check for odd and even numbers

  to divide even numbers with odd numbers

  to divide even numbers with either 1 or 0

  to create odd numbers with even variables

 19. MOD can also be used to _______________________________.
num1 % num2 == 0

  check if any number is oddly divisible by another even number

  check if any number is evenly divisible by another

  check to see if any even number is actually odd

  check if a number can be divided by zero

 20. x++ is the same as:

  x = x+11

  x = x + 1

  x+1+1

  x = x * 1

 21. This code sets x to z * 2 (4), y to y divided by 2 (5 / 2 = 2) and z = to z + 1 (2 + 1 = 3).
int x = 3;
int y = 5;
int z = 2;
x = z * 2;
y = y / 2;
z++;

  FALSE

  TRUE

 22. This code subtracts one from x, adds one to y, and then sets z to to the value in x - y minus the current value of y.
int x = 0;
int y = 1;
int z = 2;
x--; // x followed bythe double minus sign
y++;
z+=y;

  TRUE

  FALSE

 23. x += y is the same as:

  x = xy+1

  x = y+y

  x = xy

  x = x + y

 24. x *= y is the same as x = x * y

  FALSE

  TRUE

 25. x = / y is the same as x = x / y.

  FALSE

  TRUE