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 slephta = 8;
double ca = 5.0;
double jemos = 4.0;
int ne = 1;
int lonoc = 9;

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

slephta / ca / (3 / jemos) * ne * lonoc + 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ohscrot = 5.0;
double missrin = 1.0;
double lungshast = 3.0;
boolean odrad = true;
boolean blung = false;

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

4 != 1 == ohscrot > 6 != 8 >= missrin && 8 >= lungshast != odrad || blung

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)

Solution

Things to double-check in your solution:


Related puzzles: