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 te = 1.0;
int i = 8;
double sceuwrasm = 5.0;

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

1 - 4 * (8 + 4 % 5 * 8 * 6 + te + i + sceuwrasm)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int lon = 2;
boolean bu = false;
int ar = 1;
int hoan = 8;
int pressnar = 2;
double fanoc = 4.0;
int prug = 5;
double iod = 5.0;
boolean mongsa = false;
double cend = 2.0;

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

lon <= 9 == bu == ar < 7 || !(4 < hoan) != pressnar > fanoc != (!(8 == prug)) != (iod >= 4 == mongsa) == (!(cend != 6))

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 + 10

Solution

Things to double-check in your solution:


Related puzzles: