当前位置: 代码迷 >> J2SE >> java char 储存中文
  详细解决方案

java char 储存中文

热度:78   发布时间:2016-04-23 20:07:53.0
java char 存储中文
public class ChineseTest {  
    public static void main(String[] args) {  
        // 将一个中文汉字赋值给一个char变量  
        char a = '中';  
        char b = '文';  
        char c = '测';  
        char d = '试';  
        char e = '成';  
        char f = '功';  
        System.out.print(a);  
        System.out.print(b);  
        System.out.print(c);  
        System.out.print(d);  
        System.out.print(e);  
        System.out.print(f);  
    }  
}  

编译没有报错,运行结果:
中文测试成功

上面引用的是某博客的 http://gaolixu.iteye.com/blog/413284 的内容。
开始觉得是对的。不过从c++过来的 char占一个字节,而java的char占2个字节。想想也是对的。 不过自己用IDE的时候直接不能编译,说不能够把string转为char。。。。。

求大侠解答

------解决思路----------------------
用了双引号吧
  相关解决方案