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 ec = 1;
int e = 6;
int ci = 3;
int leiral = 4;

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

7 + (ec * e * ci - leiral * 3 + 4) * 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ongnong = 2.0;
int wiolmen = 7;
int acril = 5;
boolean pi = false;
double el = 4.0;
double iru = 4.0;
double inaght = 3.0;
double biasstun = 5.0;
int horm = 5;
double phim = 5.0;

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

ongnong != 7 != (!(wiolmen == acril)) || pi != (!(el == iru)) && inaght > biasstun && 8 <= horm != 7 <= phim

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: