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 treem = 3.0;
double ongun = 5.0;
int uss = 5;
double bi = 4.0;
int se = 7;
int jede = 7;
int beremp = 1;

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

treem + (ongun + 4 + uss / bi) + se / jede % 8 + beremp % 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double iocwe = 2.0;
int prerost = 1;
double gophpria = 4.0;
double molcon = 1.0;
int prismtrae = 9;
boolean mentil = true;
boolean ni = true;
double cec = 5.0;
int usbe = 4;
int er = 4;

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

iocwe >= prerost == (0 == 6) || gophpria == 9 && 6 <= molcon == 0 > prismtrae == mentil != !!ni != (0 == cec) && usbe <= er

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

Solution

Things to double-check in your solution:


Related puzzles: