基本数据类型的转换
package day03;
public class DateTypeDemo1 {
public static void main(String[] args) {
// 基本数据类型间的转换:
int a = 5;
long b = a;//自动转换
int c = (int)b;//强制类型转换
long d = 5;//自动类型转换
double e = 5;//自动类型转换
System.out.println(e);//5.0
long f = 10000000000L;
int g = (int)f;
System.out.println(g);//强转可能会发生溢出
double h = 25.9876;
int i = (int)h;
System.out.println(i);//强转有可能丢失精度
}
}
注解:基本数据类型的转换
基本数据类型从小到大依次为:
byte,short,int,long,float,double
1)
1.1)自动类型转换:小类型到大类型
1.2)强制类型转换:大类型到小类型
(要转换成为的数据类型)变量
强转有可能溢出或丢失精度