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 cae = 7;
int mi = 1;
int easnion = 6;
int ru = 6;
double sentscress = 5.0;

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

cae + (mi - easnion - ru % 7 - sentscress / 0) / 8 - 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int oi = 2;
double renic = 1.0;
boolean stri = true;
boolean resia = true;
boolean in = false;
double seaiss = 1.0;
double a = 5.0;
double neueng = 3.0;

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

(oi >= renic != !(8 < 7) && stri != resia == in) == (0 != seaiss) != a > neueng && 2 != 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"

Solution

Things to double-check in your solution:


Related puzzles: