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 cel = 4.0;
int phra = 8;
int caphpre = 1;
double spetre = 5.0;

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

5 / cel % phra % caphpre % 3 / 7 * 8 - spetre

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double thrusm = 3.0;
boolean ceur = true;
boolean fi = true;
double rard = 4.0;
double se = 3.0;
boolean icosm = true;

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

thrusm < 6 != ceur && fi == (rard == se) == !icosm && 5 > 9 && !(0 > 4)

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"

Solution

Things to double-check in your solution:


Related puzzles: