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 thur = 4;
int co = 4;
int cint = 2;
int abreur = 3;

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

9 + thur * co * 8 * cint - 6 - 3 + abreur

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int cio = 2;
double kei = 3.0;
int gucjo = 2;
boolean thiopor = false;
double eossi = 2.0;
int de = 1;

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

!(3 != 3) && cio < 9 && !(5 != 6) != kei <= gucjo && thiopor && (eossi <= de == (0 == 3))

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: