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 ou = 1;
double a = 1.0;
double o = 3.0;
double focad = 3.0;
double an = 4.0;

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

1 - 2 + 3 + (6 - ou - 9 + a) * o - focad * an

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean swo = true;
int blomam = 6;
int u = 7;
double uige = 4.0;
boolean ceslass = true;
int ziemed = 3;
int sphi = 9;

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

swo && !(blomam >= u) != (1 < uige == (1 == 3) || !ceslass) == ziemed < 3 == sphi < 6 != 8 >= 9 == (3 != 5)

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

Solution

Things to double-check in your solution:


Related puzzles: