char 占2个字节
范围为
public class TestChar {
public static void main(String[] args) {
char testChar = 'a';
System.out.println(testChar);
}
}
输出为
a
如果这样
public class TestChar {
public static void main(String[] args) {
char testChar = 'a';
System.out.println(testChar + 0);
}
}
输出为
97
这是因为char + int , char 会被自动向上转型为int, ‘a’ 的 ACSII 码为97
public class TestChar {
public static void main(String[] args) {
char testChar = 'a';
System.out.println(testChar + "0");
}
}
输出为
a0
char + String 一起, char会被转为String类型输出