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 robi = 2;
int vinoc = 7;
double hi = 5.0;

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

1 % robi % 5 / vinoc % 8 + 2 - 4 % 9 + hi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double tensi = 4.0;
boolean flen = true;
double grounnu = 2.0;
boolean stia = true;
boolean mic = false;
double cearom = 3.0;
int bromp = 3;
int sance = 4;

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

tensi == 1 != !flen || grounnu != 2 == 4 > 1 == !stia != mic != cearom >= bromp == (7 == sance)

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: