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 gantsod = 8;
double i = 4.0;
int e = 7;
double phlun = 5.0;
double mamho = 2.0;

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

gantsod + (4 % i % 6 % e - phlun / mamho % 2)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean sousm = true;
int pe = 5;
int aspheal = 8;
double hormun = 4.0;
double o = 5.0;
double co = 1.0;
double in = 5.0;
boolean rodis = false;

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

sousm != pe >= 1 || aspheal < 3 && 9 <= 7 || (hormun != o || co <= in && rodis)

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: