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 e = 2.0;
int tasac = 5;
int ad = 2;

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

5 % e - 6 * 5 / tasac * 3 - 1 % ad / 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int nir = 7;
boolean sceck = true;
boolean wordes = false;
int soron = 1;
int whedfric = 9;
int langs = 6;
int ro = 3;
double ie = 1.0;
boolean giang = false;

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

nir > 7 || sceck == wordes || soron > whedfric && 1 != 3 && langs <= ro && ie > 6 != giang

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: