public static void main(String[] args) {
/* 1.boolean不能和其他七基本数据类型进行转换 */
boolean bolVal = true;
// int i = bolVal; //报错无法进行转换
/** 2.强制类型转换,数据可能会丢失精度 */
double douVal = 100.999;
System.out.println("douVal = " + douVal);
int intVal = (int) douVal;
System.out.println("intVal = " + intVal);
/** 3.强制类型转换,数据可能会溢出 (我们所说的溢出是超过了存储的范围,导致的数据溢出) */
byte byteVal = 100;
byteVal = (byte) 128;
System.out.println("byteVal = " + byteVal);
/**
* byte 的表示范围是 -128 ~ 127
* 127 + 1 = 128
* 128超过了127 所以会显示 -128
*
* 128 + 1 = 129
* 129超过了127 所以会显示 -127
*
* 。。。。。依次
*/
/** 4.byte,show,char 三种类型的变量在进行运算(+)的时候,首先会提示为int类型,在参与运算 */
short shortVal = 100;
short shortValue = 100;
int val = shortVal + shortVal;
System.out.println("val = " + val);
/* 为什么可能会损失精度 不会损失精度的例子 */
byte byteValue = 10;
byte byteVar = 10;
byte byteValues = (byte) (byteValue + byteVar);
System.out.println("byteValues = " + byteValues);
}