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 on = 5.0;
int boting = 8;
double hechof = 3.0;
int hiales = 3;

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

8 / on + boting - 1 / hechof - 6 + 1 * 9 + hiales

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double stoiss = 2.0;
int celas = 2;
int irdha = 6;
boolean paspa = false;
int ilt = 1;
boolean io = true;
boolean neprism = false;
int egtar = 3;
double apra = 5.0;

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

stoiss == 0 == !(celas < irdha) == !paspa == (ilt != 7) == io && !neprism && egtar >= 3 == (5 == apra)

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: