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 snon = 3;
double niobo = 1.0;
double qepa = 4.0;

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

2 * snon - 7 / 7 / 1 + niobo - 7 / qepa

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean fe = false;
boolean ia = true;
boolean enval = true;
boolean primcad = false;
double arl = 1.0;
int nieflioss = 5;

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

fe != ia == enval && primcad || 9 > 2 || 8 > 3 != arl < nieflioss

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: