Agatha Haddock (112233445)
COMP-202A, Section 0 (Fall 2010)
Instructor: Cuthbert Calculus
Assignment 1, Question 3 (c)
Order of evaluation for (((q*12-(4*(z/x)+100)*y-z)%5)/2+283)
For x = 4, y = 6, z = 11
q = 7.0
1. the / in 'z/x' = 2
2. the * in '4*(z/x)' = 8
3. the + in '4*(z/x)+100' = 108
4. the * in 'q*12' = 84.0
5. the second * in '(4*(z/x)+100)*y' = 648
6. the - in 'q*12-(4*(z/x)+100)*y' = -564.0
7. the second - in 'q*12-(4*(z/x)+100)*y-z' = -575.0
8. the % = 0.0
9. the / in '((q*12-(4*(z/x)+100)*y-z)%5)/2' = 0.0
10. the + 238 in '((q*12-(4*(z/x)+100)*y-z)%5)/2+283' = 283.0
NOTE: this is the order of evaluation taught in class. Java actually uses a
slightly different order that is *equivalent*. The real Java evaluation order
for this expression is shown is Mathieu's solution.