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 usclor = 4.0;
double em = 1.0;
double tren = 1.0;
double ciss = 3.0;
int es = 6;

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

(usclor / em * 8 % tren / 1 + ciss % 2) + 2 + es

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double kasded = 4.0;
boolean sasm = false;
boolean isstre = false;
boolean on = false;
int trall = 6;
double goecrio = 1.0;
double ha = 5.0;
boolean asew = false;

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

3 < kasded || sasm && isstre && on && trall >= goecrio && 1 < 7 == ha < 8 != asew

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"

Solution

Things to double-check in your solution:


Related puzzles: