My web site - Chapter 2 Introduction to Java Applications 77 Java
Chapter 2 Introduction to Java Applications 77 Java operation Arithmetic operator Algebraic expression Java expression Addition + f + 7 f + 7 Subtraction p c p -c Multiplication * bm b * m Division / x x / y x / yor –or x y y Modulus % r mod s r % s Fig. 2.16 Arithmetic operators. Arithmetic expressions in Java must be written in straight-line form to facilitate entering programs into the computer. Thus, expressions such as adivided by b must be written as a/b, so that all constants, variables and operators appear in a straight line. The following algebraic notation is generally not acceptable to compilers: a b Parentheses are used in Java expressions in the same manner as in algebraic expressions. For example, to multiply atimes the quantity b+c, we write a * ( b + c ) Java applies the operators in arithmetic expressions in a precise sequence determined by the following rules of operator precedence, which are generally the same as those followed in algebra: 1. Operators in expressions contained within pairs of parentheses are evaluated first. Thus, parentheses may be used to force the order of evaluation to occur in any sequence desired by the programmer. Parentheses are at the highest level of precedence. In cases of nested or embedded parentheses, the operators in the innermost pair of parentheses are applied first. 2. Multiplication, division and modulus operations are applied next. If an expression contains several multiplication, division or modulus operations, the operators are applied from left to right. Multiplication, division and modulus operators have the same level of precedence. 3. Addition and subtraction operations are applied last. If an expression contains several addition and subtraction operations, the operators are applied from left to right. Addition and subtraction operators have the same level of precedence. The rules of operator precedence enable Java to apply operators in the correct order. When we say that operators are applied from left to right, we are referring to the associativity of the operators. We will see that some operators associate from right to left. Figure 2.17 summarizes these rules of operator precedence. This table will be expanded as additional Java operators are introduced. A complete precedence chart is included in Appendix C. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services