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 nu = 4.0;

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

6 - (7 - nu) % 6 - 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean cheor = true;
int i = 7;
double el = 5.0;
boolean to = false;

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

cheor || (i >= 7 && 0 >= el && to)

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

Solution

Things to double-check in your solution:


Related puzzles: