Java Reference
In-Depth Information
47 }
48 }
49 }
The program can handle simple numbers, as in the following sample execution:
This program evaluates prefix
expressions that include the
operators +, -, *, / and %
expression? 38.9
value = 38.9
It can also handle expressions with a single operator, as in the following execution:
This program evaluates prefix
expressions that include the
operators +, -, *, / and %
expression? + 2.6 3.7
value = 6.300000000000001
And it handles the case we considered that involved a product of two sums:
This program evaluates prefix
expressions that include the
operators +, -, *, / and %
expression? * + 2.6 3.7 + 5.2 18.7
value = 150.57000000000002
In fact, it can handle arbitrarily complex expressions, as in the following sample
execution:
This program evaluates prefix
expressions that include the
operators +, -, *, / and %
expression? / + * - 17.4 8.9 - 3.9 4.7 18.4 - 3.8 * 7.9 2.3
value = -0.8072372999304106
The expression being computed in the previous example is the prefix equivalent of
the following infix expression:
((17.4 - 8.9) * (3.9 - 4.7) + 18.4) / (3.8 - 7.9 * 2.3)
 
Search WWH ::




Custom Search