go to previous page   go to home page   go to next page hear noise

Answer:

x: 100  y: 100

Sometimes Either Order Works

When a variable is not part of a larger expression it makes no difference if you use the prefix operator or the postfix operator. For example:

count++ ;

++count ;

The following loop prints the values from 0 to 9, just as did the previous version (which used a postfix operator):

int counter = 0;

while ( counter < 10 )
{
  System.out.println("counter is now " + counter );
  ++counter ;
}

It is wise to use the ++ operator only with an isolated variable, as above. Using it in more complicated expressions is never necessary and can lead to nasty bugs. Java allows this only because it is familiar to C programmers. The language C allows this because it was familiar to assembly language programmers of the PDP-8 computer, a common minicomputer of the 1970s.

Our 21st century programming language Java inherits some of its features from the architecture of an ancient computer!


QUESTION 7:

Is subtracting one from a variable a common operation?