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 mentda = 8;
double a = 3.0;
int nass = 6;
int zattra = 8;
double grosqash = 3.0;

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

4 * 6 + mentda * 8 * a * 2 / 2 + (nass % zattra) * grosqash + 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean sophbec = false;
boolean eoldor = false;
boolean si = false;
int pricsaic = 6;
boolean roa = false;
boolean heass = false;
double dioprep = 3.0;
double siorchong = 1.0;

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

sophbec == eoldor || !si && 7 != pricsaic || !(!(8 > 5)) || 3 == 3 && roa != (!(8 != 4)) != heass != dioprep <= siorchong

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: