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 go = 3;
int cu = 1;
double ris = 3.0;
double bidphi = 3.0;
int woing = 5;
double wiscer = 1.0;

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

go + cu - (1 + 0 - ris) * bidphi / woing + 8 % wiscer

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean usic = true;
int cii = 9;
double bimat = 5.0;
boolean paet = false;
boolean ansped = false;
boolean serad = true;
int sengper = 2;
double hapang = 5.0;
boolean heapos = true;
boolean enstid = false;

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

!!usic != !(cii < bimat) || paet != ansped != serad && sengper > hapang || (heapos != enstid)

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: