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 draes = 4.0;
double cas = 2.0;
int smoi = 9;
int cinan = 7;
double plusbla = 5.0;

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

4 + draes * 7 + cas / 9 * smoi + cinan - 9 % 3 % 3 - plusbla + 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int casiss = 6;
double leem = 4.0;
boolean jum = false;
boolean hacle = false;
double tretac = 4.0;
boolean whohan = false;
boolean fladbein = true;
boolean po = true;
boolean ma = false;
boolean prulpi = false;
double foehus = 2.0;

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

casiss == leem || (jum || hacle && 1 <= tretac == whohan == fladbein) && po == ma != 5 > 6 != prulpi == 5 >= foehus

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" + "12"

Solution

Things to double-check in your solution:


Related puzzles: