关于java字符串拼接的笔记

最近在看 java编程思想 这本书,看到字符串操作符部分,有一个书上的例子感觉很好,记录一下。

public class E05
{
	public static void main(String[] args)
	{
		int x = 0,y = 1, z = 2;
		String s = "x,y,z"; 
		System.out.println(s + x + y + z);//如果表达式以一个字符串起头,那么后续的操作数都必须是字符串类型(编译器会自动转换成字符串)
		System.out.println(x + " " + s );
		s += "(sunmmed) = ";
		System.out.println(s + (x+y+z));
		System.out.println(""+x);//实现int转换成String 
	}
}/*OutPut:
x,y,z 012

0 x,y,z

x,y,z (summed) = 3

0

*/


猜你喜欢

转载自blog.csdn.net/minose/article/details/79476077