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 cangluch = 5;
double sphistro = 2.0;
int testscro = 2;

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

(4 % 7 * cangluch % sphistro / 9 / testscro) - 6 * 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double jor = 2.0;
boolean grie = false;
boolean as = true;
double hedsac = 4.0;
int jewsen = 9;
int pliasssa = 4;
double rarpi = 3.0;
double ephar = 1.0;

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

jor < 8 != grie != as == hedsac >= 5 || jewsen <= pliasssa && 1 == 3 || !(rarpi > ephar)

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)

Solution

Things to double-check in your solution:


Related puzzles: