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 gadtur = 3;
int kont = 3;
double doti = 5.0;
int miabis = 4;

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

3 + gadtur - kont % 9 % 5 - (9 * doti * miabis) + 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ithsent = 6;
double ba = 2.0;
int lird = 9;
int cron = 4;
boolean edmar = true;
int i = 7;
boolean cinru = true;
int riongsstres = 8;
double chrothprong = 2.0;

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

ithsent == 1 && 3 < ba || 4 != 1 && lird == cron == edmar == 2 >= i || cinru && riongsstres != chrothprong

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: