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 it = 8;
int de = 1;
double iangra = 3.0;
double od = 4.0;
double eslo = 2.0;

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

0 % 8 * (8 + 7 / it % de) * 2 % iangra * 9 * od + eslo

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int chahen = 7;
boolean mu = false;
double chapep = 3.0;
int se = 7;
int pressass = 8;
int e = 3;
double wunpiss = 5.0;
boolean zom = true;
boolean fo = true;
double sian = 4.0;
double erhe = 5.0;

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

8 > chahen != mu && chapep < se && !(pressass <= e) == !(0 <= wunpiss) != (7 != 6) == !zom && fo == sian < erhe != !(4 >= 2)

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 + "11"

Solution

Things to double-check in your solution:


Related puzzles: