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 erla = 1;
int thesoilch = 7;
int i = 7;
int riock = 2;
double aglo = 3.0;
int plequl = 3;

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

erla % thesoilch - i - riock % 6 % aglo % (2 % plequl)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double de = 1.0;
double edmuc = 3.0;
int un = 6;
int mafnic = 9;
int oa = 5;
double kihess = 4.0;
boolean zaph = true;

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

de > 5 || edmuc != 3 != (3 != un) == mafnic <= oa != 6 <= 2 && kihess >= 4 != zaph

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: