98 Part II: (Web site developers) Writing Your Own Java Programs

98 Part II: Writing Your Own Java Programs chances) to type the variable name incorrectly. With simple expressions like numberOfBunnies++, these advantages hardly make a difference. But with more complicated expressions, like inventoryItems[(quantityReceived-* itemsPerBox+17)]++, the efficiency and accuracy that you gain by using ++and –are significant. Statements and expressions You can describe the pre- and postincrement right way. When you see ++ or –, you can and pre- and postdecrement operators in two think in terms of time sequence. But occasion- ways: the way everyone understands them and ally some programmer uses ++or –in a con- the right way. The way that I explain the con-voluted way, and the notions of before and cept in most of this section (in terms of time, after break down. So, if you re ever in a tight with before and after) is the way that everyone spot, think about these operators in terms of understands it. Unfortunately, the way every-statements and expressions. one understands the concept isn t really the First, remember that a statement tells the computer to do something, and an expression has a value. (I discuss statements in Chapter 3, and I describe expressions elsewhere in this chapter.) Which category does numberOfBunnies++ belong to? The surprising answer is both. The Java code numberOfBunnies++is both a statement and an expression. Assume that, before the computer executes the code out.println(numberOfBunnies++), the value of numberOfBunniesis 28. As a statement, numberOfBunnies++tells the computer to add 1 to numberOfBunnies. As an expression, the value of numberOfBunnies++is 28, not 29. So, even though the computer adds 1 to numberOfBunnies, the code out.println (numberOfBunnies++)really means out.println(28). Now, almost everything you just read about numberOfBunnies++ is true about ++numberOfBunnies. The only difference is that as an expression, ++numberOfBunnies behaves in a more intuitive way. As a statement, ++numberOfBunniestells the computer to add 1 to numberOfBunnies. As an expression, the value of ++numberOfBunniesis 29. So, with out.println(++numberOfBunnies), the computer adds 1 to the variable numberOfBunnies, and the code out.println(++numberOfBunnies)really means out.println(29).
Our facility is located in Orlando, Florida. Our Orlando web hosting data center gives you assurance that your website will work smoothly . Check more in Orlando Web Hosting.

Leave a Reply