字符char和ASCII对应的值运算,字符串String输出易犯错误

package com.web;

public class Test47 {
    
    
    public static void main(String[] args) {
    
    
        String str1 = "abc";
        String str2 = "abc";
        char c = '!';
        char c0 = 'a';
        char c1 = 97;
        char c2 = 1+'a';
        char c3 = 27+'a';
        char c4 = 30+'a';
        char c5 = 'a'-77;
        char c6 = 'a'+100;
        char c7 = 1;
        char c8 = 0;
        char c9 = 127;
        System.out.println("c = " + c);//c = !
        System.out.println("c0 = " + c0);//c0 = a
        System.out.println("c1 = " + c1);//c1 = a
        System.out.println("c2 = " + c2);//c2 = b
        System.out.println("c3 = " + c3);//c3 = |
        System.out.println("c4 = " + c4);//c4 =  删除
        System.out.println("c5 = " + c5);//c5 = 
        System.out.println("c6 = " + c6);//c6 = ?,ASCII码对应的值不超过127,字符的数值[0,127]
        System.out.println("c7 = " + c7);//c7 =  标题开始
        System.out.println("c8 = " + c8);//c8 =  空字符NUL (NULL)
        System.out.println("c9 = " + c9);//c9 =  删除

        boolean b = str1==str2;
        System.out.println("a"+"abc"+"bcd");//aabcbcd
        System.out.println("str1==str2 is "+b);//str1==str2 is true
        System.out.println("str1==str2 is "+str1==str2);//false 直接拼接了布尔值和字符串
        System.out.println("str1==str2 is "+(str1==str2));//str1==str2 is true
        System.out.println("str1==str2 is "+'\''+str1==str2);//false转义也没用
    }
}

猜你喜欢

转载自blog.csdn.net/djydjy3333/article/details/121521103
今日推荐