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 chiied = 7;
int co = 8;
double gedca = 2.0;
double ainalm = 2.0;
int pe = 4;

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

chiied + co / gedca / 5 + ainalm + 9 + 2 % pe

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double masqe = 5.0;
boolean qoss = false;
boolean treng = true;
boolean ste = true;
int etris = 2;
boolean wapre = false;
double birmang = 3.0;

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

(masqe >= 4 != !qoss && treng && ste) && etris >= 1 == wapre == birmang >= 9

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: