System.out.println(SEX1+SEX2)錯在哪里
final char SEX1 = '男'; final char SEX2 = '女'; ? ? ? ?/*下面這種是錯誤的 ?????? ? ? ? ?//正確的是 ? ? ? ?System.out.println(SEX1); ? ? ? ?System.out.println(SEX2); ? ? ? ?//或者 ? ? ? ?System.out.printf("%c,%C",SEX1,SEX2); 為什么上面這種寫法就是錯誤的呢
2017-05-15
public class HelloWorld{
? ?public static void main(String[] args) {
//char 表示的是 0-65535的數(shù)字?
? ?final char SEX1 = '男';
? ?final char SEX2 = '女';
? ? ? ?System.out.println((int)SEX1);//30007
? ? ? ?System.out.println((int)SEX2);//22899
? ? ? ?System.out.println(SEX1+SEX2);//52906 = 30007+22899
? ? ? ?//因?yàn)閖ava中, String類型的+ ?表示連接 . char byte int long等的四則運(yùn)算都是一樣的
? ? ? ?System.out.println(SEX1);
? ? ? ?System.out.println(SEX2);
? ? ? ?System.out.println(""+SEX1+SEX2);//利用String的加法連接字符串,返回結(jié)果還是String ,進(jìn)行輸出 ? ?
2017-04-23
為什么字符類型的常量不可以在輸出的時候使用System.out.println(SEX1+SEX2);這種來輸出。這樣寫會輸出一串?dāng)?shù)字
2017-03-21
final char SEX1 = '男'; final char SEX2 = '女'; ? ? ? ?/*下面這種是錯誤的 ?*/ ? ? ? ? ? ? //正確的是 ? ? ? ?System.out.println(SEX1); ? ? ? ?System.out.println(SEX2); ? ? ? ?//或者 ? ? ? ?System.out.printf("%c,%C",SEX1,SEX2);?