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 e = 5;
int se = 3;
int ple = 2;
double ew = 1.0;
double lassfa = 4.0;

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

e * 9 / se % ple / ew % 8 / 1 % 6 * 1 * lassfa

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double gropriul = 5.0;
double easshad = 3.0;
int schew = 7;
int niroul = 9;
boolean scesfred = false;
double sto = 3.0;
boolean he = false;

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

gropriul <= 0 != (easshad == schew) != niroul >= 6 || (!(1 != 6) != scesfred && 7 == 4) || 3 < sto != !he && 5 != 3

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: