Decrement Operator

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes.

Decrement Operator

The operator -- is a postfix and a prefix decrement operator. The postfix operator decrements a variable after using its value; the prefix operator decrements a variable before using its value.

ExpressionOperationExampleResult
x++ use the value, then add 1int x = 10;
int y;
y = x++ ;
x is 11; y is 10
++x add 1, then use the valueint x = 10;
int y;
y = ++x ;
x is 11; y is 11
x-- use the value, then subtract 1int x = 10;
int y;
y = x-- ;
x is 9; y is 10
--x subtract 1, then use the valueint x = 10;
int y;
y = --x ;
x is 9; y is 9

Inspect the following code:

int x = 99;
int y = 10;

y = --x ;

System.out.println("x: " + x + "  y: " + y );

QUESTION 8:

What does this fragment write out?