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 tedhe = 2.0;
double es = 5.0;
int psiant = 6;
double eaden = 2.0;
int gruri = 4;

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

tedhe * es * 3 - 0 + 6 + psiant + eaden - gruri

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ca = false;
double eing = 5.0;
int sois = 4;
double oodspe = 4.0;
double mihud = 2.0;
int prith = 6;
boolean ocot = true;

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

ca || eing > sois || 6 <= 6 == (oodspe != mihud) == prith > 8 && ocot || 7 >= 1

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: