public static void main(String[] args) {
//1.类型赋值
//a.赋值整数--对应Ascii码
char a = 66;//B
char b = 97;//a
System.out.println(a);
System.out.println(b);
//b.赋值字符--单引号括起来的是字符型的直接量
char c = 'a';//a
char d = '\u4e2d';//中
System.out.println(c);
System.out.println(d);
char e = 1;//
char f = '1';//1
System.out.println(e);
System.out.println(f);
//c.赋值中文--每个中文占两个字节
char x = '中';
System.out.println(x);
int h = '中';//20013
System.out.println(h);
//经典面试题
/*
char m='a';
char res = m+1;
char res2='a'+1;
为什么res会出错误?怎么改?为什么res要强转,而res2不需要?
*/
char m = 'a';
char res = (char) (m + 1);
char res2 = 'a' + 1;
System.out.println(res);
System.out.println(res2);
/*
char res = m+1;是一个变量和一个常量参与合并,m+1自动转为整形,无法直接赋值给char,所以要强转
char res2=‘a’+1;是两个常量参与合并,编译时不用类型转换自动合并。
*/
}