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 tro = 5;
int erp = 5;
int pren = 4;
int osem = 9;
double va = 2.0;
int priong = 1;

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

tro / 9 * erp + pren * osem / va / priong / 0 * 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean icju = false;
int thingse = 4;
int nu = 6;
boolean okdan = true;
int i = 6;
boolean sengdo = true;
boolean tesspe = true;
double psar = 4.0;
int thii = 1;

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

icju || thingse >= nu != okdan == 1 >= i || sengdo || tesspe || 5 != psar || 0 <= thii

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: