Drawing ASTs for expressions: Correct Solution


For each of the Java expressions below:

Be sure that your tree accurately reflects how Java would evaluate the expression.

Part 1

Given the following variables:

int bruss = 8;
double ipoi = 2.0;
double urscid = 2.0;
double ic = 3.0;
double trangs = 1.0;

...draw the AST and evaluation results for the following expression:

bruss * ipoi + urscid / 0 - 9 * 1 / ic - 5 % 1 + trangs

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int inpatch = 2;
boolean mudbox = true;
boolean ebal = true;
double ti = 5.0;
double timses = 1.0;
boolean ohoof = true;
double en = 2.0;

...draw the AST and evaluation results for the following expression:

4 != inpatch != (0 == 8) || mudbox != 5 > 6 || 3 >= 1 == ebal != ti < timses && ohoof && 5 >= en

Solution

Things to double-check in your solution:


Part 3

Draw the AST and evaluation results for the following expression:

0 + 1 + 2 + 3 + 4 + "5" + 6 + 7 + 8 + "9" + 10

Solution

Things to double-check in your solution:


Related puzzles: