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 sphicrhin = 9;
double ni = 4.0;
double remied = 2.0;
int ilhim = 8;
int erm = 5;

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

sphicrhin + 5 + (0 * ni % 3 / remied * 2 % ilhim) * erm / 8 + 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean thiel = true;
int hecek = 9;
double de = 2.0;
double qar = 2.0;
int pri = 5;
boolean sedme = false;
int crelsin = 4;
boolean biagus = true;
double snass = 4.0;
int stao = 3;
double pei = 1.0;
int twede = 1;

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

!thiel || !(hecek <= de) && 9 > 9 == qar >= 2 || pri >= 0 != sedme == crelsin < 2 && biagus != snass < stao == pei >= twede

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 + 10 + "11"

Solution

Things to double-check in your solution:


Related puzzles: