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 eamel = 4.0;
int ec = 3;
double dre = 1.0;
int ro = 4;
double ma = 3.0;

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

eamel % ec % dre / 2 / 3 - ro / ma / 3 * 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double a = 3.0;
int noid = 7;
boolean mecpa = false;
boolean prisos = true;
int pe = 7;
int niss = 8;
int phast = 5;
boolean noss = true;

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

5 != a == (2 == noid) == mecpa && prisos != 9 >= 0 == pe > niss != phast < 8 && noss

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"

Solution

Things to double-check in your solution:


Related puzzles: