- Integers and decimals can have an error because the decimal is converted to a binary number, which can be an infinite loop decimal, such that an integer is converted to a floating-point, and then the result of the operation is forced to transform:
int n = (int) 10-24.0/5;
- Rounding tips, you can first convert the floating point number + 0.5, and then convert to an integer:
INI n = (int//
- In a Boolean operation, once a condition is computed with the operation and or operation, the result is no longer running:
Public classBooleantest { Public Static voidmain{intn = 0; BooleanA = 5/n;//will be an error Booleanand = (5 < N) && (5/n);//returns false as long as there is a condition that does not meet the criteria to return and stop the subsequent calculation Booleanor = (5 > 0) | | (5/n);//returns true as long as one satisfies the condition and returns and stops the subsequent calculation
System.out.println (and);
System.out.println (or);
} }
- The ternary operator (B?X:Y), which calculates X or y based on the condition, calculates only one, and the type of x and Y must be the same.
int n = +; Boolean positive = n >= 0; int abs = positive? N:-N;
- Char and string are primitive type characters and reference type strings, the reference type means that the variable itself points to a string, and changing the value of the string variable simply modifies the pointer to the variable and does not have the value of the table string.
- Integers and decimals can have an error because the decimal is converted to a binary number, which can be an infinite loop decimal, such that an integer is converted to a floating-point, and then the result of the operation is forced to transform:
int n = (int) 10-24.0/5;
- Rounding tips, you can first convert the floating point number + 0.5, and then convert to an integer:
INI n = (int) (12.5 + 0.5); 13
- In a Boolean operation, once a condition is computed with the operation and or operation, the result is no longer running:
public class Booleantest {public static void main{ int n = 0; Boolean a = 5/n; Will error Boolean and = (5 < N) && (5/n);//return False if one does not meet the condition to return and stop after the calculation of Boolean or = (5 > 0) | | (5/n); Returns true as long as one satisfies the condition and returns and stops the subsequent calculation
System.out.println (and);
System.out.println (or);
} }
- The ternary operator (B?X:Y), which calculates X or y based on the condition, calculates only one, and the type of x and Y must be the same.
int n = +, Boolean positive = n >= 0; int abs = positive? N: -N;
- Char and string are primitive type characters and reference type strings, the reference type means that the variable itself points to a string, and changing the value of the string variable simply modifies the pointer to the variable and does not have the value of the table string. Characters are represented by single quotation marks, and strings are denoted by double quotation marks.
- Array, the same type of data can be created as an array. An array is an object of a reference type.
int New int [5];//Type [] Initializes an array, int[] Each value defaults to 0 after initialization, and the array size is immutable when initialized
Arr[0] = 56;
Arr[1] = 44;
ARR[2] = 65;
ARR[3] = 45;
ARR[4] = 90;
Array length can be obtained by arr.length
You can not specify an array size, which is automatically calculated by the compiler:
int[] ns = new int[] {68,34,43,24,54,45};
Can be further shortened to:
Int[] ns = {68,34,43,24,54,45};
Numerical operations for getting started with Java