LastLaugh.java
public class LastLaugh
{
public static void main(String args[])
{
System.out.print("H" + "a"); //Ha
System.out.println('H' + 'a'); //169
}
}
但 + 和char型同时出现的时候,分清运算是字符串连接运算还是简单的算术运算。
JSL 5.1.2、5.6.2
Puzzle 12:
Abc.java
public class Abc
{
public static void main(String[] args)
{
String letters = "ABC";
char[] numbers = {'1', '2', '3'};
char [] chars = {'a', 'b', 'c'};
System.out.println(letters + "easy as " + numbers); // ABCeasy as [C@de6ced
System.out.println(letters + " easy as " + chars); // ABC easy as [C@c17164
System.out.println(numbers); // 123
System.out.println(chars); // abc
}
}
关于数组的,参见JSL 10