De acuerdo con Wikipedia, los códigos Unicode (en hexadecimal) para las cartas de poker tienen el siguiente patrón: comienzan con 1F0
, luego una letra, de la A
a la D
; después un número o letra, del 1
al 9
o de la A
a la E
.
❐ Código:
En Java es posible representar un número en hexadecimal de manera literal. Sólo hay que añadir el prefijo 0x
al número deseado. Y esto se puede aprovechar para crear dos ciclo for
anidados, uno para el primer carácter y el otro para el segundo carácter. Es decir:
for (int c1 = 0xA; c1 <= 0xD; c1++) {
for (int c2 = 1; c2 < 0xE; c2++) {
String str = String.format("1F0%X%X", c1, c2);
int codePoint = Integer.parseInt(str, 16);
System.out.printf("%c U+%s %s%n", codePoint, str, Character.getName(codePoint));
}
}
c1
va de 0xA
a 0xD
y c2
va de 0x1
a 0xE
, tal como se requiere.
❐ Salida:
🂡 U+1F0A1 PLAYING CARD ACE OF SPADES
🂢 U+1F0A2 PLAYING CARD TWO OF SPADES
🂣 U+1F0A3 PLAYING CARD THREE OF SPADES
🂤 U+1F0A4 PLAYING CARD FOUR OF SPADES
🂥 U+1F0A5 PLAYING CARD FIVE OF SPADES
🂦 U+1F0A6 PLAYING CARD SIX OF SPADES
🂧 U+1F0A7 PLAYING CARD SEVEN OF SPADES
🂨 U+1F0A8 PLAYING CARD EIGHT OF SPADES
🂩 U+1F0A9 PLAYING CARD NINE OF SPADES
🂪 U+1F0AA PLAYING CARD TEN OF SPADES
🂫 U+1F0AB PLAYING CARD JACK OF SPADES
🂬 U+1F0AC PLAYING CARD KNIGHT OF SPADES
🂭 U+1F0AD PLAYING CARD QUEEN OF SPADES
🂱 U+1F0B1 PLAYING CARD ACE OF HEARTS
🂲 U+1F0B2 PLAYING CARD TWO OF HEARTS
🂳 U+1F0B3 PLAYING CARD THREE OF HEARTS
🂴 U+1F0B4 PLAYING CARD FOUR OF HEARTS
🂵 U+1F0B5 PLAYING CARD FIVE OF HEARTS
🂶 U+1F0B6 PLAYING CARD SIX OF HEARTS
🂷 U+1F0B7 PLAYING CARD SEVEN OF HEARTS
🂸 U+1F0B8 PLAYING CARD EIGHT OF HEARTS
🂹 U+1F0B9 PLAYING CARD NINE OF HEARTS
🂺 U+1F0BA PLAYING CARD TEN OF HEARTS
🂻 U+1F0BB PLAYING CARD JACK OF HEARTS
🂼 U+1F0BC PLAYING CARD KNIGHT OF HEARTS
🂽 U+1F0BD PLAYING CARD QUEEN OF HEARTS
🃁 U+1F0C1 PLAYING CARD ACE OF DIAMONDS
🃂 U+1F0C2 PLAYING CARD TWO OF DIAMONDS
🃃 U+1F0C3 PLAYING CARD THREE OF DIAMONDS
🃄 U+1F0C4 PLAYING CARD FOUR OF DIAMONDS
🃅 U+1F0C5 PLAYING CARD FIVE OF DIAMONDS
🃆 U+1F0C6 PLAYING CARD SIX OF DIAMONDS
🃇 U+1F0C7 PLAYING CARD SEVEN OF DIAMONDS
🃈 U+1F0C8 PLAYING CARD EIGHT OF DIAMONDS
🃉 U+1F0C9 PLAYING CARD NINE OF DIAMONDS
🃊 U+1F0CA PLAYING CARD TEN OF DIAMONDS
🃋 U+1F0CB PLAYING CARD JACK OF DIAMONDS
🃌 U+1F0CC PLAYING CARD KNIGHT OF DIAMONDS
🃍 U+1F0CD PLAYING CARD QUEEN OF DIAMONDS
🃑 U+1F0D1 PLAYING CARD ACE OF CLUBS
🃒 U+1F0D2 PLAYING CARD TWO OF CLUBS
🃓 U+1F0D3 PLAYING CARD THREE OF CLUBS
🃔 U+1F0D4 PLAYING CARD FOUR OF CLUBS
🃕 U+1F0D5 PLAYING CARD FIVE OF CLUBS
🃖 U+1F0D6 PLAYING CARD SIX OF CLUBS
🃗 U+1F0D7 PLAYING CARD SEVEN OF CLUBS
🃘 U+1F0D8 PLAYING CARD EIGHT OF CLUBS
🃙 U+1F0D9 PLAYING CARD NINE OF CLUBS
🃚 U+1F0DA PLAYING CARD TEN OF CLUBS
🃛 U+1F0DB PLAYING CARD JACK OF CLUBS
🃜 U+1F0DC PLAYING CARD KNIGHT OF CLUBS
🃝 U+1F0DD PLAYING CARD QUEEN OF CLUBS
──────────────
NOTA: Dependiendo del navegador (y a veces también del sistema operativo), los caracteres anteriores podrán ser renderizados correctamente: 🂡🂢🂣🂤🂥🂦🂧🂨🂩🂪🂫🂬🂭🂱🂲🂳🂴🂵🂶🂷🂸🂹🂺🂻🂼🂽🃁🃂🃃🃄🃅🃆🃇🃈🃉🃊🃋🃌🃍🃑🃒🃓🃔🃕🃖🃗🃘🃙🃚🃛🃜🃝
UPDATE
El código se modifica, de acuerdo con los comentarios del OP, como sigue:
for (int c1 = 0xA; c1 <= 0xD; c1++) {
for (int c2 = 1; c2 < 0xE; c2++) {
if (c2 != 0xC) {
String str = String.format("1F0%X%X", c1, c2);
int codePoint = Integer.parseInt(str, 16);
System.out.println(Character.toChars(codePoint));
}
}
}