Try It Yourself: Arithmetic Expressions

  1. Assume you have been given: int x = 8, y = 7, z = 1;
    double a = 2.0, b = 3.5;
    Evaluate the following expressions: y * 2 + x / 3
    (a + 3.0) * -b + 4.5
    x % 5 + y * a
    y / a + b - x / (-4 + y)
    Math.sqrt(x * (y + z))

  2. What is the value of r after the following code executes: int p = 3;
    int q = p * 7;
    p = 4;
    int r = q / p;

  3. Assume you have been given: final int QUAD = 4;
    Write a Java code fragment to compute:
    Two expressions in traditional mathematical notation. Expression 1: (x+7)/y + 3/(x QUAD)  Expression 2: (4/7)cos(1 + 1/(square root(pi+x)))