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 cangsil = 8;
double utri = 5.0;
int trioss = 7;
int chelis = 7;
int bisken = 4;

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

3 - (2 / cangsil - utri * trioss / 4 - 7 % 3 + 6) * chelis % bisken

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean kodrua = true;
double glangbes = 2.0;
boolean heaboid = true;
boolean spraps = true;
boolean bri = true;
boolean cantagn = true;
int nespod = 5;
int merkbes = 4;

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

kodrua && glangbes >= 9 && !(0 <= 7) == !!heaboid != (spraps == bri != cantagn) == (nespod != 8) != merkbes >= 3 == !(8 <= 9)

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 + 11

Solution

Things to double-check in your solution:


Related puzzles: