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 ede = 7;
int iel = 3;
int chec = 7;
int pistud = 9;
double kotrech = 4.0;
double deuziol = 5.0;

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

6 - (ede * iel - chec / 5 * 4 + pistud * kotrech) - deuziol

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ibio = false;
int salvi = 5;
int gallthrem = 3;
int grembo = 1;
double pidcosm = 2.0;
int giot = 9;
boolean badoush = true;
int ac = 6;
double pido = 4.0;
int ma = 4;

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

2 != 7 && ibio && (salvi < gallthrem == grembo < 7 == (pidcosm != giot)) != badoush && ac > 9 != pido <= ma

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"

Solution

Things to double-check in your solution:


Related puzzles: