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 esmglud = 4;
int peudplod = 2;
double pel = 1.0;
double o = 5.0;
double tir = 4.0;
int joatret = 9;

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

(esmglud % peudplod % 4) - pel * o * tir % 4 % joatret

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean sti = false;
double em = 5.0;
int di = 9;
boolean omo = true;
boolean io = true;
boolean trentqen = true;
boolean gless = false;

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

sti && 0 == em && 8 >= di && omo == io && trentqen != gless

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

Solution

Things to double-check in your solution:


Related puzzles: