Я пытаюсь распечатать красное сердце и пока что пришел полностью пустым, вот некоторые из моих попыток: < /p>
Попытка 1: < /strong> < /p>
.
Код: Выделить всё
String input = "❤️"; // A red heart, what I'm HOPING will print into the terminal
System.out.println("output: " + input); // the "straight up copy and paste" method
< /code>
Результат: < /p>
output: ??
Код: Выделить всё
String input = "❤️"; // A red heart, what I'm HOPING will print into the terminal
int codePoint = input.codePointAt(0) ; // converts the red heart to a Decimal Code Point
System.out.println("codePoint: " + codePoint); // prints the code point to ensure its printing the right thing
String output2 = Character.toString(codePoint); // converts the code point to a red heart
System.out.println("output2: " + output2); // the "convert the codepoint to a string direct" method
< /code>
Результат: < /p>
codePoint: 10084
output2: ?
Код: Выделить всё
String output3 = Character.toString(10084);
System.out.println("output3: " + output3); // the "convert the codepoint to a string indirect" method
< /code>
Результат: < /p>
output3: ?
Код: Выделить всё
System.out.println("output4: " + "\u2764\uFE0F"); // the "unicode" method
< /code>
Результат: < /p>
output4: ??
Код: Выделить всё
PrintWriter printWriter = new PrintWriter(System.out,true);
char output5p1 = '\u2764';
char output5p2 = '\uFE0F';
printWriter.println("output5: " + output5p1 + output5p2); // the "printWriter + char" method
< /code>
Результат: < /p>
output5: ??
codePoint: 10084
output: ❤️
output2: ❤
output3: ❤
output4: ❤️
output5: ❤️
< /code>
Результаты с использованием UTF-16 LE: < /p>
codePoint: 10084
output: ❤️
output2: ❤
output3: ❤
output4: ❤️
output5: ❤️
< /code>
Проблема в том, что я обнаружил, что другие символы Unicode работают просто хорошо: < /p>
System.out.println("output: " + "\u00FF"); // the last char on the Latin 1 Supplement char set
System.out.println("output2: " + "\u0100"); // the first char on the extended Latin 1 char set
< /code>
Результат: < /p>
output: ÿ
output2: ?
< /code>
Первый символ печатает, как и ожидалось, тогда как второй отпечатки в качестве вопроса. Из того, что я видел, моей первой попытки было достаточно. Первоначально он напечатал красное сердце без проблем. Уверенность, однако, что я. src = "https://i.sstatic.net/dduk38u4.png"/>
Подробнее здесь: https://stackoverflow.com/questions/797 ... -in-vscode
Мобильная версия