Java String + 与 =

来源:互联网 发布:淘宝电话人工服务电话 编辑:程序博客网 时间:2024/06/05 22:36

例子1:

System.out.println("is"+ 100 + 5);System.out.println(100 + 5 +"is");System.out.println("is"+ (100 + 5));

输出:
is1005
105is
is105

例子2:

public class Test{    public static void main(String argv[]){        String str = "hello";        str += 100;  // hello100        str = str+100; // hello100100        str = 100; // error: can not convert from int to String        str = (String)100; // error: can not cast from int to String        System.out.println(str);    }}
原创粉丝点击