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 o = 7;
double priar = 4.0;

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

o % 6 % 4 % 7 + (9 % priar * 6) % 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double cheshwiorn = 1.0;
int sa = 4;
double fonass = 2.0;
boolean odvum = true;
boolean fliti = false;
int hioong = 9;

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

8 == 1 != (cheshwiorn < sa && 2 > 5 || 9 <= fonass) == odvum || fliti == (hioong != 6)

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: