Variable
Integral type
BYTE 1 byte, data range: -128~127
Short 2 bytes, data range: -32768~32767
int 4 bytes, data range: -2147483648~2147483648
Long 8 bytes, data range: -263~263-1
Floating point Type
Float 4 bytes, data range: -3.403e38~3.403e38
Double 8 bytes, data range: -1.798e308~1.798e308
Character type
Char 2 bytes, data range: Represents a character
Boolean type
Boolean 1 byte, data range: True and False
Defining variables
Data type variable name = data value;
int a = 1;
Considerations for using Variables
1, the variable can not be assigned after the value, the use of the assignment, no assignment can not be used
2 . Scope restrictions when using variables
3. variables cannot be defined repeatedly
Data type conversions
Automatic type conversion : Represents a data type with a small range converted to a large range of data types
Automatic type conversion format: Data type variable with large range = data type value with small range;
Coercion type conversion: A data type that represents a large range of data types converted to a small range
Coercion type conversion format: Data type variable with a small range = (data type of small range) range large data type value;
Operator: the symbol used to calculate the data. The data can be constants, or it can be variables.
Precautions:
1, the addition operator in connection with the string, note that only directly with the string will be converted to a string
2, Division "/" when the two sides are integers, take the integer part, the remainder. When one side is floating-point, divide by normal rule
3, "%" is divided into the remainder of the symbol, the fractional surplus is meaningless. The result symbol is the same as the remainder symbol
4, integer do dividend, 0 can not do divisor, otherwise error
Use of arithmetic operator + + 、--
+ +,--operator, the value of variable A is increased by 1 or self-minus 1 after the operation is performed using the original value of variable A.
++,--operator precedes, increment the value of variable a by 1 or decrement by 1, and then participate in the operation with the new updated value
Assignment operators
= assigned value
+ = plus equals
-= minus equals
*= multiply equals
/= except equal to
%= modulo equals
Used to complete the assignment of the data
+ =,-, *=,/= Such an assignment operator contains a cast operation that will result in both left and right operations, forcing the type to be converted to the left
Comparison operators
= = equals
! = does not equal
< less than
> Greater than
<= less than or equal to
>= greater than or equal to
Used to compare the size of the data (e.g. 1>2)
The result of the comparison is a Boolean value of type bool
the "= =" Two equal signs indicate whether the comparison is equal, "=" an equal sign represents an assignment
logical operators
& and
| Or
^ XOR or
! Non -
&& Short Circuit and
|| Short Circuit or
Logic and & and logic short-circuit and &&: Represents and means, the right and left sides must be conditional, the result is true;
Logical OR | and logical short-circuit or | | : represents or means that there is a condition on both sides of the left, and the result is true;
Logical non!: Represents the opposite meaning, originally false, the result is true; originally a ture, the result is false;
Logical xor ^: the left and right side conditions result is the same, the result is false, left and right side conditions result is different, the result is true;
Ternary operators
Format: (conditional expression)? Expression 1: Expression 2;
Determine the value of the conditional expression first, if true, the result of the operation is an expression of 1; if false, the result of the expression is 2
Java Learning day02