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 stintbri = 3;
double rarncont = 3.0;
int casphu = 9;
double on = 2.0;
int i = 3;

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

stintbri / 7 % (rarncont % casphu - 5 * on) / i + 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double e = 5.0;
int mobon = 2;
boolean co = false;
boolean asmtha = false;
int o = 8;
double in = 3.0;
int psurdin = 1;
int wimpas = 5;

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

e >= 0 || 4 > mobon != co || asmtha || 6 != o || !(in >= 6) || psurdin >= wimpas

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"

Solution

Things to double-check in your solution:


Related puzzles: