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 ix = 7;
double od = 4.0;
int oo = 2;
double hidde = 2.0;
int ic = 7;

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

ix / od * oo / 3 + hidde % ic * 8 % 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int io = 8;
int sont = 7;
boolean pio = true;
double slea = 2.0;
double rioac = 2.0;
int proungfi = 8;

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

8 != io != 6 > sont == pio || slea <= 0 || rioac >= 7 != 0 >= 5 != proungfi > 7

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: