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 essro = 4;
double vi = 4.0;
int fric = 2;
double o = 1.0;
int ed = 6;
int ou = 5;
int ebdo = 2;

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

9 % essro * vi * fric % 9 % o * 2 % ed / ou % ebdo * 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int na = 2;
int a = 9;
int se = 7;
double hoth = 1.0;
boolean secscon = false;
boolean bapeing = true;
int reo = 2;
boolean phor = false;
double madgish = 2.0;
double prulppruss = 3.0;

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

na >= a || se != hoth && secscon || !bapeing != 0 < reo || 9 < 6 || phor && 7 >= 5 != madgish >= 3 == (4 == prulppruss)

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: