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:

double rosh = 2.0;
double purnork = 2.0;

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

9 % 5 % (9 % 1 - rosh * 9) - purnork * 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean groba = false;
double er = 3.0;
boolean un = true;
int a = 4;
double bissod = 1.0;
boolean cror = true;

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

groba != (8 == er) && un || 9 != a || 4 == bissod == (6 == 3) && cror

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: