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 pleapleou = 1;
double du = 1.0;
int edfriap = 6;
double ca = 5.0;
int omod = 6;

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

9 % 6 * (pleapleou % du) - edfriap - ca / 1 + omod

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean tred = false;
boolean wopre = false;
double iean = 3.0;
double he = 1.0;
boolean ufi = false;
int som = 6;

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

!tred || 9 > 5 == wopre != 7 < iean == ((he == 4) && ufi == !(6 <= som))

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

Solution

Things to double-check in your solution:


Related puzzles: