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 prass = 3;
int jia = 5;
double spakun = 2.0;
double fes = 5.0;
int la = 2;
int u = 3;

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

prass - jia + 0 / 2 + spakun * fes + la / u

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean rar = false;
boolean ilir = false;
boolean ciomcet = false;
int greupal = 3;
int menges = 9;
double a = 5.0;
int theas = 4;
boolean sertit = false;

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

rar && ilir == ciomcet && greupal == menges && 6 > a && theas <= 1 && sertit

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

Solution

Things to double-check in your solution:


Related puzzles: