基本类型和对象类型进行计算以及自动类型转换
来源:互联网 发布:大学手机必备软件 编辑:程序博客网 时间:2024/05/29 09:48
/** * 猜测:基本类型和对象类型进行计算时,可以互相转换 * 自动类型转换--位数少的自动向位数多的转换 */package test;import java.math.BigInteger;import java.util.ArrayList;import java.util.Arrays;public class Test {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubString s = "";if(s==s+0){//字符串连接System.out.println("shello world");}System.out.println(s+0);Integer in = 1;if(in==in+0){//trueSystem.out.println("inhello world");}System.out.println(in+2);//整型对象可以直接加intSystem.out.println(in+2.5);//3.5-----求解释??猜测:基本类型的对象类型进行计算时,对象类型自动转为基本类型int x = in+3;System.out.println(x);in = in+4;System.out.println("in = "+in);int i = 1;if(i==i+0){System.out.println("ihello world");}char c = 1;if(c==c+0){//首先c转为int(因为0是int),再加0,然后从int转为charSystem.out.println("chello world");}if(c==c+0.2){//falseSystem.out.println("c2hello world");}System.out.println(c+0.2);//位数少的自动向位数多的转换float f = 1;if(f==f+0){System.out.println("fhello world");}double l = 1;if(l==l+0){System.out.println("lhello world");}String sx = "";//空字符串不等于null----空字符串也是对象,有可访问地址的。null表示地址为0,不可以访问。if(sx == null){System.out.println("sxhello world");}}}