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 le = 4;
int io = 8;
int ticka = 9;
int biwran = 3;
double glodan = 5.0;
int po = 1;
double nied = 1.0;

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

2 * le + io - 8 + 6 * ticka * 7 * biwran / glodan / po + nied

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean seoi = false;
int stige = 4;
int chenmo = 5;
double cung = 5.0;
double va = 5.0;
int pidta = 6;
double phropast = 5.0;
double coc = 1.0;
int stac = 4;
int mepen = 1;

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

seoi || stige >= chenmo != cung > 1 == (8 != va) != 2 >= 3 || pidta != 2 && 5 != phropast == coc >= 4 && stac < 4 && 0 != mepen

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: