Java basic summary (numeric type conversion rules)
I. numeric type conversion rules
When numeric data is computed, if the type of the operand is different or the type of the operand is lower than that of the int type
Automatic type conversion is performed. The specific rules are as follows:
1) if one of the two operands is double, the system first converts the value of the other operand to double.
Type, and then perform the operation. Otherwise
2) If one of the two operands is float, the system first converts the value of the other operand to float.
Type, and then perform the operation. Otherwise
3) If one of the two operands is long, the system first converts the value of the other operand to long
Type, and then perform the operation. Otherwise
4) The values of both operands are converted to the int type.
5) If there is only one operand (for example "~ "Bit operation) and its type is lower than the int type, the value of this operand is converted to the int type
It is simply as follows:
1) byte, short, char-> int-> long-> float-> double
2) byte, short, and Char are not converted to each other before calculation. The three of them are converted to the int type before calculation.
Note: in Java, Int-type numeric constants can be directly assigned to corresponding low-level byte, short, and char variables,
No forced type conversion is required, as long as it does not exceed the value range of the variable.
Binary Boolean operation
& Logical and, | logical or, & short circuit and | short circuit or
& | "Short Circuit": when the result of the entire expression can be determined based on the value of the first operand,
The second operation value is calculated and the final result is obtained. For example, when the expression "a & B" is calculated,
If the result of A is false, you can determine that the calculation result of "and" can only be false, so the value of B is not calculated,
The final result is false.
3. Differences between flow control statement break and continue
1. The break statement is used to terminate the running of the switch statement or loop statement. In a loop statement, the format of the break statement can be divided into two types:
Break; // terminate the running of the (inner) single-layer loop statement.
Break <tag>; // in a multi-layer nested loop, terminate the operation of the outer loop marked by the tag.
2. The function of the continue statement is to end the running of the loop statement, that is, to skip the subsequent loop body.
Statement to start the next loop. Continue:
Continue; // skip the running of the (inner) single-layer Loop
Continue <tag>; // in a multi-layer nested loop, this operation of the outer loop marked by the tag is skipped,
Start the next operation.
The following isProgram, Carefully understand the usage of continue
/**
* Output a prime number between 100 and 200
* Skip nested loops using the continue statement
*/
Package com. javase;
/**
* @ Author johnston678
*
* @ Version 2009-03-06
*/
Public class primenumber {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Int n = 0;
Outer:
For (INT I = 101; I <200; I + = 2) {// outer loop
For (Int J = 2; j <I; j ++) {// Inner Loop
If (I % J = 0)
Continue outer; // cannot use "break"
}
System. Out. Print (I + "/t ");
N ++;
If (n <6)
Continue;
System. Out. println (); // output six data records and then wrap them.
N = 0;
}
}
}
This articleArticleSource: Liu zhimeng blog Source: http://www.liuzm.com/article/java/0900525.htm