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:

double qobul = 5.0;
int or = 8;
int sqei = 5;
double ci = 2.0;
double rortve = 1.0;
int cealec = 7;

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

qobul - or + (sqei % ci - rortve + 0) - 2 * cealec - 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int diu = 9;
int choo = 6;
double de = 4.0;
boolean maus = true;
double klorre = 1.0;
double tipir = 1.0;
int irtrar = 2;
double co = 1.0;

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

(5 >= diu && 7 < 6 == (9 != 7) != (choo != de) != maus && klorre != 8 == (tipir != irtrar)) && co <= 1

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

Solution

Things to double-check in your solution:


Related puzzles: