简体   繁体   中英

I can't figure out why DrJava won't output Unicode symbols

I'd like to apologize upfront for my incredible newb-ness with regard to Java and programming in general. But I've searched everywhere for an answer to this and I just can't seem to find one.

So I'm simply trying to run the following:

public class WriteSquares2
{
  public static void main(String[] args)
  {
    for (int i=1; i<=10; i++)
    {
      System.out.println(i + " \u2261 " + (i % 7) + " modulo 7");
    }
  }
}

The Unicode character \≡ is the congruence sign (≡). DrJava shows the following as output:

1 ? 1 modulo 7
2 ? 2 modulo 7
3 ? 3 modulo 7
4 ? 4 modulo 7
5 ? 5 modulo 7
6 ? 6 modulo 7
7 ? 0 modulo 7
8 ? 1 modulo 7
9 ? 2 modulo 7
10 ? 3 modulo 7

What's weirdest about this is that when I simply type

'\u2261'

into the Interactions box, I get the equivalence character in single quotes:

'≡'

I've tried simply putting '\≡' in the code instead of " \≡ ", but then I get stuff like this:

8803 modulo 7
8805 modulo 7
8807 modulo 7

I also tried just simply inserting the unicode character into the code, but that just gave an error message. Can anyone figure out what's going on or what I'm doing wrong? Your help is much appreciated.

[I should add that this isn't a homework assignment or anything, as our book barely even mentions Unicode - just trying to figure this out ... and when I started, I didn't think it would be this hard!]

EDIT: I'm using Mac OS 10.7.5 and Dr Java says its build is "drjava-20120818-r5686".

EDIT #2: Here's a screenshot using Monospaced 12 as my main font. It still shows up as question marks, even though I can get the console to return me the symbol if I type it in directly, but with single quotes.

在此输入图像描述

The issue has to do with the font you're using, it is not a problem with your code. See DrJava's settings under Edit > Preferences > Display Options > Fonts > Main Font .

DrJava using default font (Monospaced 12) on Linux: Linux上的DrJava,“Main Font”设置为默认值(Monospaced 12)

DrJava using a different font (PT Sans 12) on Linux: Linux上的DrJava,“Main Font”设置为“PT Sans 12”

Both screenshots are from the same instance of DrJava; I didn't even have to shut it down. Note that in the Interactions pane, the glyph is correct for my Monospaced font and is a generic placeholder for PT Sans. The same occurs in the Console tab (not shown).

I did a bit research, and I found a solution that was found before from another question here

So in this case, it might be something similar. Not really your code, but the way DrJava handles unicode depending on your system.

" Character encoding depends on the system. Depending on your box, it may print the 16 bits of the UTF-16 encoding (which is 9794), the high 8 bits (which would be 38) or, as in your case, the low 8 bits (which is 66).

9794 / 256 = 38
9794 % 256 = 66

"

您是否已将提示更改为以unicode输出。(注意英语世界的Java默认值为IS0-8859-1)。

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.

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