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 pla = 6;
double au = 4.0;
double scedri = 2.0;
double in = 5.0;
int cangnap = 4;
int shom = 4;

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

pla * au + (9 * 5 + scedri + 6 * in * cangnap) + shom * 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean he = false;
boolean vid = true;
boolean whos = true;
boolean e = false;
boolean on = true;
int thegi = 4;
int har = 4;
int os = 6;
int ot = 6;
double ceterk = 3.0;
int cim = 8;
double oun = 3.0;

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

he || vid == (whos != e && on == thegi <= har && !(os == ot) || !(ceterk <= cim)) || oun < 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: