Wednesday, 5 December 2012

Changing the Order of Precedence

             Multiplication and division always take precedence over addition  and subtraction when an expression is calculated. However, force parts of an expression to be calculated first with the aid of parentheses.

Example:

<html>
<head>
<title>Operator Precedence</title>
</head>
<body>
<h3>Operator Precedence</h3>
<p>
15 - 4 * 2 + 8 / 2 = <%=15-4*2+8/2 %>
<br>
(15 - 4) * 2 + 8 / 2 = <%=(15-4)*2+8/2 %>
<p>
</body>
</html>


Description:

Type an expression that includes addition,subtraction,multiplication and division.Use the expression tag to print the result to the Web page.

Place parentheses around values that need to be calculated first.Parentheses change the order of precedence.

****************************OUTPUT*******************************************

Operator Precedence

15 - 4 * 2 + 8 / 2 = 11
(15 - 4) * 2 + 8 / 2 = 26 

*******************************************************************************

No comments:

Post a Comment