Java 有趣的字符(串)

import java.io.*;
class test  
{
	public static void main (String[] args) throws java.lang.Exception
	{

        
        int n1='a';
        System.out.println(n1); //97
        
        char n2=(char)n1;
        System.out.println(n2);//a,如果n2ui是int類型,和例子1一樣結果
        
        int n3='\u0041';
        System.out.println(n3);//65



	}
}
import java.io.*;
class test  
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    // Unicode兼容ASCII編碼
		int a = 72;
        int b = 105;
        int c = 65281;
        // FIXME:
        // String s = ""+(char)a + (char)b + (char)c;//join String together
        // System.out.println(s);
        //String s1=""+a+b+c;
        
        //System.out.println(s1);//7210565281
	
	    String s2 = (char)a + (char)b + (char)c;// error: int cannot be converted to String
        System.out.println(s2);
        
        String s3 = ''+(char)a + (char)b + (char)c;// error: unclosed character literal,int cannot be converted to String
        System.out.println(s3);
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章