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 cio = 3.0;
double seasna = 3.0;
int eoc = 2;

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

1 - cio - 2 % seasna / 3 - 0 - eoc * 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean da = true;
int ka = 1;
int luss = 6;
double sqen = 5.0;
int chliantta = 9;
double priono = 3.0;
boolean gri = false;

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

da || ka > 5 == 6 > luss != (2 != 7) != sqen >= chliantta && 2 > priono || gri

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"

Solution

Things to double-check in your solution:


Related puzzles: