Java基本数据类型——类型转换

(一)基础知识

Java数据类型:byte(1),short(2),int(4),long(8),boolean(1),char(2),float(4),double(8)
*自动类型转换:byte->short,   char->int->long->float->double,低->高,不会发生精度损失
*强制类型转换:高->低,可能会发生数据溢出和精度损失

(二)代码实现

public class change_dateType {
	
	public static void main(String[] args) {
				//自动转换无精度损失
		        int i=100;
		        long l=i;
		        System.out.println("l="+l);
		     
		        //强制类型转换
		        double x=9.997;
		        int n=(int)x;       
		        System.out.println("n="+n);
         }
}
发布了61 篇原创文章 · 获赞 61 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_42475914/article/details/100754968