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 falrel = 7;
int an = 4;
int cothriss = 7;

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

4 % 4 * 2 % 4 * 7 % 2 / 8 % falrel + an / cothriss

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int i = 3;
int tinii = 4;
double po = 2.0;
double tet = 5.0;
boolean qio = true;
boolean chehe = true;
double trarbrid = 4.0;
double enmo = 4.0;
int picger = 7;
boolean thasm = true;

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

i >= 9 == tinii <= po || 4 < tet != qio && 3 <= 7 || chehe && trarbrid == enmo || picger >= 6 && thasm

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: