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 osssung = 7;
int er = 1;
int bru = 8;

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

osssung + 3 * er % 4 % 4 / (7 / bru + 1) + 1 * 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean kaght = false;
double biang = 3.0;
int tistlir = 8;
double sceipdi = 4.0;
int rer = 6;
boolean thompep = false;
double oicsplol = 2.0;
boolean punsan = false;

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

kaght && biang > 0 != 6 >= tistlir == (sceipdi == rer) == thompep && !(!(0 != 6)) && oicsplol != 3 && punsan == (8 == 7)

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: