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 a = 7;
int u = 4;
double vempod = 2.0;
int epin = 8;
int foptrosm = 4;

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

a % 2 - 4 - u - vempod / epin * 8 * 8 + 3 / foptrosm + 3 / 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean twadea = false;
boolean mixger = false;
boolean aen = true;
double ca = 5.0;
int piri = 8;
int un = 8;
int ple = 5;
int usmar = 1;
double dalpeic = 3.0;
double ea = 5.0;
int o = 9;
boolean ab = false;

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

twadea || mixger && aen && !(3 == ca) != (6 == piri) && un == ple != 6 > usmar == dalpeic <= 2 || 6 == ea && 4 != o == !ab

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" + 11 + 12

Solution

Things to double-check in your solution:


Related puzzles: