2

I'm attempting to print a deck of cards to system.out, with the suits represented by ♥, ♦, ♣, and ♠. I've copy-pasted the characters into my code:

deck.offer(new Card(v, (i == 0) ? "\u2666" : (i == 1) ? "♦" : (i == 2) ? "♣" : "♠"));

As you can see, I've tried escaping the symbols and directly pasting them into my code. Eclipse (the IDE that I use) gave me the option to change the encoding of the .java file to UTF-8, but my System.out.print()'s still show '?' as the symbols.

How do I print ♥, ♦, ♣, and ♠ to the terminal?

EDIT: Oleski answered my question below. Thank you!

James Box
  • 35
  • 1
  • 9
  • 1
    Which terminal are you using? Maybe you have to configure your terminal to UTF-8. Look in the options. – Guillaume F. Sep 16 '17 at 03:34
  • 1
    You should check your console/terminal to see what code pages it supports. EG PC473 the original IBM code page contains these characters, but at different codes... – Usagi Miyamoto Sep 16 '17 at 03:44
  • 2
    Possible duplicate of [Display special characters using System.out.println](https://stackoverflow.com/questions/10933620/display-special-characters-using-system-out-println) – Raju Sharma Sep 16 '17 at 03:51

1 Answers1

1

It's possible that the terminal you're viewing the characters in is not interpreting them as UTF-8. That is, the characters are encoded in UTF-8 correctly, but the terminal is not set to interpret them as UTF-8

Oleksi
  • 12,947
  • 4
  • 56
  • 80
  • This is the issue. A quick duckduckgo search got me to [this](https://stackoverflow.com/questions/17385818/eclipse-character-encoding#17385876) page, which fixed my problem. Thank you! Also, to anyone trying to find the Run Configurations menu, it's not under Preferences. It's under the Run menu. – James Box Sep 16 '17 at 03:43