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 aron = 2.0;
int zansec = 6;
double anstir = 4.0;
int congplus = 6;

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

1 - 9 - aron - 6 * 4 % zansec % anstir - congplus * 6 % 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean fogec = false;
boolean uirm = true;
boolean ang = true;
double niecois = 5.0;
double ropre = 4.0;
double shos = 3.0;
double rortmia = 2.0;
int chish = 8;
int civin = 4;
int sparvu = 8;

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

fogec || uirm && ang || (niecois <= ropre || shos != 2 && 1 != rortmia == 3 < 1 || chish > 9) == (civin != sparvu)

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: