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 amad = 4;
int aenin = 4;

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

1 + amad / (1 - 0 + aenin / 4 / 9 + 7)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean haph = true;
boolean af = false;
int u = 7;
boolean imiss = true;
double etel = 3.0;
int alpa = 9;
int olmui = 9;
boolean wa = true;

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

haph && af && !(9 < u) || imiss == 1 > etel == alpa >= olmui != wa

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: