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 prorhod = 2.0;
int garism = 2;
int gialun = 1;

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

0 + 3 % 5 - prorhod % 5 * garism % gialun

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean tresups = true;
double zass = 3.0;
int ve = 4;
double a = 1.0;
boolean pherm = false;

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

!tresups != 7 >= zass || 9 != ve == ((a != 3) || pherm) != (!(5 != 3))

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: