标签:添加 void 自动转换 强制转换 col byte class ble 表示
public class DataTypeSwitch{ public static void main(String [] args){ //自动转换、强制转换都是数值类型之间的转换 /* 自动转换: byte->short->int->long->float->double char->int->long->float->double */ byte b=10; short s=b; System.out.println(s); int i=s; long l=i; System.out.println(i); System.out.println(l); //double d=10.0; //float f=d;将大的赋值给取值范围小的,会丢失精度,如果需要转换,必须强制转换 float f=10.0f; double d=f; System.out.println(d); char c=‘a‘; i=c; System.out.println(i); //数据类型强制转换,将取值范围大的数据类型赋值给取值范围小的,需要在源数据前添加 (目的数据类型) b=(byte)i; System.out.println(b); l=(long)d; System.out.println(l); String s1="123123"; String s2="123123"; int a=Integer.parseInt(s1)+Integer.parseInt(s2); System.out.println(a); System.out.println(s1+s2);//此时的+表示字符串的拼接 } }
标签:添加 void 自动转换 强制转换 col byte class ble 表示
原文地址:https://www.cnblogs.com/fqqwz/p/11625132.html