“`
package com.zhidi.test1;
public class 类型转换 {
public static void main(String[] args) {
//整数 --> 整数,自动类型转换
byte a = 10;
short b = a;
// System.out.println(b);
//整数 --> 整数,强制类型转换
int a1 = 200;
byte b1 = (byte)a1;//容易造成数据丢失
// System.out.println(b1);
//整数型-->浮点型,自由转换
long a3 = 100;
float b3 = a3;
//浮点型-->整数型
double a4 = 129.64;
int b4 = (int) a4;
// System.out.println(b4);
//整数型-->字符型
int a5 = 52;
char b5 = (char) a5;
System.out.println("b5="+b5);
//字符型-->整数型,自动类型转换,char类型在计算机底层是以int类型来运行的
char a6 = 'a';
int b6 = a6;
System.out.println(b6);
//浮点型-->字符型
double a7 = 65.1;
char b7 = (char) a7;
System.out.println(b7);
}
}