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 duntsqes = 3.0;
int scri = 6;
double od = 2.0;
int ced = 3;
int bre = 9;
int skithund = 7;

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

5 % duntsqes * scri / od + 4 % ced % bre % skithund * 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean esgi = true;
int pedent = 1;
boolean ict = true;
int espu = 9;
int tuiist = 6;
int knosto = 6;
int arouc = 9;
boolean piunis = true;

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

esgi == pedent > 8 && ict == 3 <= 9 || espu != tuiist || knosto <= 0 != (!(arouc == 5)) == piunis

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: