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 pegim = 7;
int ca = 6;
int atchei = 8;
int isa = 5;

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

7 / pegim + 9 - ca * 4 / 2 + 4 + 7 % atchei % 8 * isa + 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int tro = 9;
boolean in = true;
double mousspsi = 5.0;
int rigrul = 6;
int e = 4;
double mecec = 4.0;
boolean proccix = true;
int feth = 1;
boolean eso = false;
int ac = 1;
int fa = 8;
int ba = 7;

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

9 <= tro == in || (!(mousspsi == rigrul) && !(e > 8) || mecec >= 2 || proccix || 3 >= feth && eso != 3 > ac && 6 != fa) == ba > 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" + 9 + "10" + 11 + 12

Solution

Things to double-check in your solution:


Related puzzles: