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 priner = 4;
double sces = 2.0;
double pra = 4.0;
int te = 9;
int croias = 7;
double riri = 2.0;

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

2 % 5 * (priner - sces) + 6 % pra - te + croias / 6 - 5 / riri

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int damfod = 5;
double ce = 1.0;
double cick = 1.0;
int crilpliss = 7;
double oce = 5.0;
boolean uiges = false;
int rosmcangs = 3;
int zi = 1;
boolean scriocad = true;
boolean pel = false;
double ar = 4.0;
boolean no = true;

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

damfod == ce || !(cick <= crilpliss) != oce >= 0 != uiges != 4 > rosmcangs == !(zi > 8) && scriocad == !pel != 0 <= ar == !no

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: