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.
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. I tried compiling this and it gives me 12 illegal character syntax errors. Any help would be greatly appreciated. ^_^
Additional Info: I am printing this to the console and I am using TextPad to compile.
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. 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文字周围使用''
以使其可编译。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.