Junior — Middle
Kas saame selgitada, mis on muutuja väärtuse vähendamine ühe võrra?
sobes.tech AI
Vastus AI-lt
In Java, the operation to decrease the value of a variable by one is usually performed using the decrement operator --. It decreases the current value of the variable by 1.
There are two forms:
- Postfix decrement:
i--— first returns the current value, then decreases. - Prefix decrement:
--i— first decreases the value, then returns.
Example:
int i = 5;
System.out.println(i--); // Will print 5, then i becomes 4
System.out.println(--i); // First i becomes 3, then prints 3