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 raqa = 9;
int gesmfra = 7;
int la = 7;
double haun = 4.0;
int pu = 8;

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

raqa * gesmfra * 4 - (la + haun / pu - 4)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean doua = true;
int i = 4;
boolean mawldeal = true;
int ce = 3;
double piafia = 5.0;
boolean in = false;

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

doua || 8 < i && mawldeal && 2 <= 5 != ce <= piafia && in

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

Solution

Things to double-check in your solution:


Related puzzles: