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