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 cais = 8;
int becid = 4;
int ipu = 9;
double doabra = 4.0;

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

(5 - cais * 7 + becid * 9 * 1 - ipu + 7 * 0 - 7) / doabra

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double oontscol = 2.0;
boolean a = true;
boolean cintpo = false;
boolean eschi = true;
int ormchur = 5;
double an = 2.0;
double eoxront = 4.0;
int flerni = 1;
boolean mitaeost = false;
double tesplish = 3.0;

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

9 <= oontscol || a != cintpo && eschi != (ormchur == 1) == (an < 4 == (2 != eoxront) && flerni >= 8 != mitaeost && tesplish == 5)

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 + 11

Solution

Things to double-check in your solution:


Related puzzles: