数据类型的转换

      short e = 99;
long f = e-1;

System.out.println(f);





}



public class demo5 {
public static void main(String[] args) {
int a = 127; // “内存溢出"
byte a1 = (byte)a; //强制转换
//高转低需要在变量名前加要转换的数据类型
System.out.println(a);
System.out.println(a1);


System.out.println("==============================================================");

int b = 1916; //低转高 自动转换
double b1 = b;

System.out.println(b);
System.out.println(b1);


//不同类型的数据必须转换为同一类型再进行运算 不能对布尔值进行转换 不能把对象类型转换为不相干的类型


System.out.println((int)23.8); //强制转换可能存在精度问题
System.out.println((int)-48.89f);



char c = 'a' ; //注意单引号
int d = c + 1 ;

System.out.println((char)d);
System.out.println(d);







}
posted @ 2021-10-29 14:04  猪肉炖粉条香香香  阅读(33)  评论(0)    收藏  举报