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 i = 4;
double malshu = 1.0;
double pugress = 4.0;
double ha = 5.0;
double duss = 2.0;
double ieud = 4.0;
double testce = 1.0;

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

9 - (i % 6 + malshu * pugress / ha - duss % ieud % 5 + testce)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ongshress = false;
boolean caeis = true;
double od = 3.0;
double hiprou = 2.0;
double etrul = 2.0;
int puana = 1;

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

9 != 5 == (5 != 6) != ongshress && (caeis != 5 > od == (2 != hiprou) == 5 <= 1 == 8 < etrul != puana >= 5)

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

Solution

Things to double-check in your solution:


Related puzzles: