Professional Documents
Culture Documents
Data Types
Data Types
Data Types
Data Type:
Integer Numbersffds
1) int −2 ×109 ¿ 2× 109
2) long −8 ×10 18 ¿ 8 ×1018
3) byte
4) short
we can store int in a long but to store large variable in long we need to put L at the end. Even though the
number is with in the range of long we need to put L at the end.
Decimal Numbers:
1) float 6 to 7 digits after decimal
2) double 15-16 digits after decimal
By default, the decimals are stored in a double, if the decimal is initialized by a float it shows error
Boolean numbers:
1) It can store only true or false.
2) The default value of the Boolean is false.
3)
Type Casting:
Implicit conversion, small capacity variable to a large capacity variable, example int to long and explicit
conversion is the reverse.
Note :
Decimal to non-decimal:
Compiler shows error in decimal to non-decimal conversion, while non decimal to decimal
happen implicitly without any error.
We need to do explicit type casting, but there will be some data loss. Digits after the decimal are
not shown.
sc.next(); takes the string till the first space.
sc.nextLine(); It takes whole line as input till enter is encountered
Operators:
Arithmetic Operators:
There are five math operators. (Plus, minus, multiplication, division, percentile).
The division sign always gives the quotient because int/int always gives the int)
Example 24/10 the result will be int so the answer is 2.4.
Relational Operations:
Logical Operators:
&&
||
Unary Operators:
Post operator will use the value of a in the current step and it increases the value of a by one for the
next step.
Pre-increment operators: