简体   繁体   English

在Java中打印Unicode占星符号

[英]Print Unicode Astrological Signs in Java

I have read several posts on both Stack Exchange and other sites, but am still a bit stuck on how I can go about printing the Astrological Signs in Java. 我已经在Stack Exchange和其他网站上阅读了几篇文章,但是对于如何用Java打印占星术符号仍然有些困惑。

public static void main(String[] args)
{
    char aa = \u2648;
    char ab = \u2649;
    char ac = \u264A;
    char ad = \u264B;
    char ae = \u264C;
    char af = \u264D;
    char ag = \u264E;
    char ah = \u264F;
    char ai = \u2650;
    char aj = \u2651;
    char ak = \u2652;
    char al = \u2653;

    while(true)
    {
        System.out.println(aa + ab + ac + ad + ae + af + ag + ah + ai + aj + ak + al);
    }
}

From what I understand, one can only use \\u when the hex value value of the unicode is inside of the range U+0000 to U+FFFF, which this is. 据我了解,只有unicode的十六进制值在U + 0000到U + FFFF范围内时,才能使用\\ u。 I tried compiling this and it gives me 12 illegal character syntax errors. 我尝试编译它,它给了我12个非法字符语法错误。 Any help would be greatly appreciated. 任何帮助将不胜感激。 ^_^ ^ _ ^

Additional Info: I am printing this to the console and I am using TextPad to compile. 附加信息:我正在将此打印到控制台,并且正在使用TextPad进行编译。

Try this. 尝试这个。 Note that you are printing the chars in an infinite loop. 请注意,您是在无限循环中打印字符。

Update: To print the unicode characters, you will have to create a new output stream using "UTF-8" encoding. 更新:要打印unicode字符,您将必须使用“ UTF-8”编码创建一个新的输出流。 Try this. 尝试这个。 It should work. 它应该工作。

public static void main(String[] args) {
    char aa = '\u2648';
    char ab = '\u2649';
    char ac = '\u264A';
    char ad = '\u264B';
    char ae = '\u264C';
    char af = '\u264D';
    char ag = '\u264E';
    char ah = '\u264F';
    char ai = '\u2650';
    char aj = '\u2651';
    char ak = '\u2652';
    char al = '\u2653';

    PrintStream out = null;
    try {
        out = new PrintStream(System.out, true, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    out.println("" + aa + ab + ac + ad + ae + af + ag + ah + ai + aj + ak + al);
}

在char文字周围使用''以使其可编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM