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 spreelcen = 8;
int ra = 4;
double treots = 4.0;
double il = 5.0;
double khiad = 3.0;

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

spreelcen / ra * treots * il * 3 - khiad * 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int aeec = 3;
int phiss = 7;
double dron = 4.0;
boolean hengfrec = false;

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

aeec >= phiss != 1 <= 3 && 3 != dron != 9 > 4 != 3 >= 7 && hengfrec

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

Solution

Things to double-check in your solution:


Related puzzles: