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 trudid = 5.0;
double esho = 4.0;
double menple = 4.0;
int en = 9;

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

5 * 5 * trudid - esho + 2 * menple + en - 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean qunbar = false;
int se = 2;
double etging = 1.0;
int alcard = 9;
int sceo = 5;
int trul = 8;
double hica = 1.0;

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

(qunbar || se != etging != alcard >= 5) != (sceo != 5) && 3 < 7 == !(4 > trul) != 7 < hica

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: