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 chreck = 4.0;
int se = 9;
double chengair = 2.0;
int trospla = 2;
int lo = 4;

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

9 % chreck % 9 + se + 0 % chengair - trospla % lo

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean smin = false;
double pi = 3.0;
double pel = 2.0;
int snealslan = 5;
double la = 4.0;
int ook = 8;
int e = 6;
boolean si = false;

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

smin || pi < 0 != (0 == 2) && 5 >= pel && (snealslan != la || ook == e) && si

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: