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 oshio = 1.0;
int cus = 7;
int rosi = 2;
double fasm = 2.0;
int ma = 6;
double sonrup = 5.0;
double fiassprad = 1.0;

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

oshio * cus % rosi % 8 - 3 / 5 - 2 * fasm / ma - sonrup / fiassprad

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double coilsac = 3.0;
boolean lae = false;
double u = 2.0;
boolean anang = false;
boolean ke = false;
double nensed = 1.0;
double prultung = 4.0;
double bepass = 1.0;

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

!(1 > coilsac) != lae || 1 != u != anang != ke == 5 >= nensed && 1 > 9 && 7 < 1 == 4 < prultung && 7 <= bepass

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

Solution

Things to double-check in your solution:


Related puzzles: