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:

double olprio = 2.0;
double po = 4.0;
double antpea = 4.0;
int bedas = 1;
double sherm = 1.0;
int isssqa = 9;
int ad = 5;
double ralad = 5.0;

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

olprio + (po * antpea / 6 * 6) % bedas - sherm * isssqa % ad % ralad

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int a = 3;
boolean rauo = false;
double adism = 1.0;
double sidrass = 4.0;
int tridpro = 1;
boolean chelek = true;
int deod = 6;

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

a != 3 != (3 == 2) == rauo == adism <= 5 || sidrass > tridpro == (4 == 0) == 1 < 7 || chelek && 8 > deod

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)

Solution

Things to double-check in your solution:


Related puzzles: