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 as = 9;
double dac = 3.0;
double noss = 1.0;

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

(as * dac) + 0 - noss - 8 - 2 + 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean el = false;
double be = 5.0;
int mared = 4;
double sqad = 5.0;
int ondres = 5;
int swe = 5;

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

5 == 2 == el == 3 <= be || mared >= 3 == (4 != sqad) != (ondres == swe)

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

Solution

Things to double-check in your solution:


Related puzzles: