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 luntroc = 2.0;
double os = 4.0;
int ilt = 8;
int stitre = 2;
double e = 4.0;
double enpe = 3.0;

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

luntroc / (os / 1 + ilt + stitre / e) % enpe

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double eswern = 4.0;
boolean pretes = false;
double em = 5.0;
int pu = 2;
int cer = 8;
int pla = 2;
double thaia = 1.0;
double prist = 1.0;
boolean piarmped = false;

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

eswern < 8 || pretes != em >= pu != (cer >= pla == (thaia != prist) && !!piarmped)

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

Solution

Things to double-check in your solution:


Related puzzles: