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 zenson = 4.0;
int todcho = 1;
double rallplo = 1.0;
int mipri = 6;
int ouss = 4;

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

7 % zenson + 3 % todcho / 7 / (rallplo + 6 * mipri + 4 + ouss) / 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double pa = 4.0;
double fu = 3.0;
double awec = 1.0;
double ne = 5.0;
int resmu = 6;
int rorben = 4;
int ranxpred = 7;
int fick = 2;
boolean sa = true;
int stasphint = 6;
double zardma = 4.0;
int ou = 6;

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

pa >= 7 || (9 <= 7 != 0 <= fu != !(awec > 9) && ne <= resmu == rorben > ranxpred == fick < 9 || sa) != 2 <= stasphint != (zardma != ou)

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: