Java -- 基础
基础知识
-
float和double的不同
-
1. Memory :
float takes 4 bytes (32 bits) where as double takes 8 bytes(64 bits).
-
2. Suffix :
By default, float numbers are double in java. In order to store them into float variable, you need to explicitly add the suffix 'f' or 'F'.
float num = 1.23456f // or float num1 = 1.23456FFor double you need to explicitly add the suffix 'd' or 'D'.
0.5 , 0.5d or 0.5D -
3. Precision :
float: 6-7 digits decimal points precision
double: 15-16 decimal points precision
-
4. Data loss :
float-> double 会有精度损失, double-> float 不会又精度损失
-
5. Default data type :
double是浮点数的默认类型,float不是
-
6. Wrapper class :
Wrapper class for float is java.lang.Float.
Wrapper class for double is java.lang.Double. -
7. Defaut value :
float default value is 0.0f.
double default value is 0.0d.
-
-
防止数字越界
System.out.println(Float.MAX_VALUE); System.out.println(Float.MIN_VALUE); System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE); System.out.println(Double.MAX_VALUE); System.out.println(Double.MIN_VALUE);输出:
3.4028235E38
1.4E-45
2147483647
-2147483648
1.7976931348623157E308
4.9E-324
问题
- 怎么在别的包内访问该包内数据?

浙公网安备 33010602011771号