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 qi = 2.0;
int aptus = 9;
int chod = 9;
double thu = 4.0;

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

6 / qi * 8 - 1 / 5 * 3 - (0 / aptus) * chod % 2 - 0 + thu

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean misgon = false;
boolean osu = true;
int raempass = 9;
double prirpe = 2.0;
double prushrorl = 4.0;
boolean al = true;
boolean istvong = true;
boolean whaped = false;
boolean in = false;
int grell = 7;
double crede = 2.0;

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

!misgon || !(8 > 0) && osu == raempass >= 9 && !(prirpe < prushrorl) == 6 <= 0 && al || istvong == whaped && in || grell != crede

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: