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 scosma = 8;
double neprur = 2.0;
int iclo = 7;

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

scosma - neprur * 7 + iclo - 7 % 5 - 4 * 0 - 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int e = 2;
boolean erm = true;
int dio = 9;
double channac = 4.0;
int si = 7;
boolean woish = false;

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

9 == e || erm == (!(dio != 6)) != (3 == 2) != 0 > channac == 3 < si || 4 <= 2 || woish

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: