package duotai2;
public class test {
public static void main(String[] args) {
int i = 1;
char c1 = '1';
char c2 = 1;
System.out.println(c2 == i); //true
System.out.println(c1 == i); // false
System.out.println(c1 == c2); //false
System.out.println(c2); //
}
}
从上面的代码可以看出char型变量存放的其实是对应的字符码的值,即存的是int型的数,那么c1的值就为’1’对应的ASC码,c2存放的就是int型的1,打印c2时,因为c2定义为char,所以打印数字1对应的字符。