数据类型 | 所占位数 | 默认值 | 取值范围 |
---|---|---|---|
byte | 8位 | 0 | [-2^7,2^7) |
short | 16位 | 0 | [-2^15,2^15) |
int | 32位 | 0 | [-2^31,2^31) |
long | 64位 | 0L | [-2^63,2^63) |
float | 32位 | 0f | |
double | 64位 | 0d | |
char | 64位 | ‘u0000‘ | ‘\u0000‘-‘\uffff‘ |
boolean | 1位 | false | true或false |
类,数组,接口都是引用数据类型
Scanner in=new Scanner(System.in);//in是new Scanner对象的引用,指向它的地址
\n换行 \t制表 \0空字符 \‘单引号 \"双引号
运算过程中,有低精度向高精度转换。
byte,short,char—> int —> long—> float —> double
注意:自动转型后数值不是四舍五入!
int i=127;
byte b = (byte)i;
注意:强制转换有可能溢出,例如上述int i=127;
改为int i=128;
Animal a = new Cat(); // 向上转型
Cat c = (Cat)a; // 向下转型
原文:https://www.cnblogs.com/weiyi2020/p/12345194.html