Bird
0
0

Given variables x = 8 and y = 3, which Ruby expression correctly calculates the remainder after subtracting y from x and then dividing by 4?

hard📝 Application Q9 of 15
Ruby - Operators and Expressions
Given variables x = 8 and y = 3, which Ruby expression correctly calculates the remainder after subtracting y from x and then dividing by 4?
Ax - (y % 4)
Bx % (y - 4)
C(x - y) % 4
D(x % y) - 4
Step-by-Step Solution
Solution:
  1. Step 1: Calculate x - y

    8 - 3 equals 5.
  2. Step 2: Calculate remainder of 5 divided by 4

    5 % 4 equals 1.
  3. Step 3: Match expression to calculation

    Only (x - y) % 4 matches the described operation.
  4. Final Answer:

    (x - y) % 4 -> Option C
  5. Quick Check:

    Subtract then modulo = (x - y) % 4 [OK]
Quick Trick: Use parentheses to control operation order [OK]
Common Mistakes:
  • Misplacing parentheses
  • Applying % before subtraction
  • Confusing operators order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes