Java Tutorial: Data Type of Expressions & Increment/Decrement Operators
Resulting data type after arithmetic operation
- Result = byte + short -> integer
- Result = short + integer -> integer
- Result = long + float -> float
- Result = integer + float -> float
- Result = character + integer -> integer
- Result = character + short -> integer
- Result = long + double -> double
- Result = float + double -> double
Increment and Decrement operators
- a++, ++a (Increment Operators)
- a--, --a (Decrement Operators)
These will operate on all data types except Booleans.
Quick Quiz: Try increment and decrement operators on a Java variable
- a++ -> first use the value and then increment
- ++a -> first increment the value then use it
Quick Quiz: What will be the value of the following expression(x).
- int y=7;
- int x = ++y*8;
- value of x?
- char a = ‘B’;
- a++; (a is not ‘C’)
Code:
Handwritten Notes: Click To Download
Ultimate Java Cheatsheet: Click To Download