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 gruvo = 8;
double no = 5.0;
int fion = 1;
double mo = 3.0;
int wentclui = 4;

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

8 + gruvo * 3 % no % 1 + fion * (mo % 4) * wentclui

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean slemhen = false;
double senen = 5.0;
boolean digha = false;
int phondu = 7;
int ac = 3;
double hiorsin = 2.0;
double e = 2.0;
int kner = 2;
int sove = 3;

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

slemhen != (9 == 7) && senen <= 4 && digha && 6 == phondu || ac == hiorsin != (0 == e) == kner > sove

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: