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 he = 3.0;
int carnust = 5;
int soame = 7;
double bengblu = 3.0;
double prol = 3.0;

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

he + (carnust + soame + 8 / 5 / bengblu) - prol % 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int skem = 3;
double vi = 1.0;
int psomcack = 2;
int pid = 6;
int epon = 6;
int ol = 7;
double ziange = 5.0;
boolean ho = true;

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

!(skem < 5) != (vi != 4) != psomcack >= 0 || 5 <= pid == 7 > epon != (!(ol == ziange)) != ho

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: