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 chax = 6;
int hesh = 6;
double osm = 1.0;
double seckchi = 3.0;

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

2 - 1 % 6 % chax * hesh / osm * seckchi % 2 % 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int irder = 2;
boolean kanrast = false;
double bisde = 1.0;
int hac = 5;
double beie = 1.0;
double prinnjor = 1.0;
int croa = 5;
boolean prir = false;
boolean sitrac = true;

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

irder < 1 || kanrast == (bisde != hac) && beie < 4 && !(5 > prinnjor) == croa >= 0 != prir || !sitrac

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: