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 ec = 6;
int bi = 5;
double humb = 2.0;
double ior = 5.0;
int ta = 4;

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

ec * bi * humb / 1 % ior * 5 % 1 - ta

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean plidtho = false;
boolean terpo = true;
double rintri = 1.0;
int soswe = 7;
double un = 2.0;
boolean hifo = false;
boolean rimsi = true;

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

plidtho && terpo || rintri <= 2 != (soswe == un) && hifo || !rimsi == 7 < 3

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: