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 \u2261 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 '\u2261' in the code instead of " \u2261 ", 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.
Unicode uses two encoding forms: 8-bit and 16-bit, based on the data type of the data that is being that is being encoded. The default encoding form is 16-bit, where each character is 16 bits (2 bytes) wide. Sixteen-bit encoding form is usually shown as U+hhhh, where hhhh is the hexadecimal code point of the character.
Unicode supports more than a million code points, which are written with a "U" followed by a plus sign and the number in hex; for example, the word "Hello" is written U+0048 U+0065 U+006C U+006C U+006F (see hex chart).
The standard, which is maintained by the Unicode Consortium, defines as of the current version (15.0) 149,186 characters covering 161 modern and historic scripts, as well as symbols, emoji (including in colors), and non-visual control and formatting codes.
An even same code may represent a different character in one language and may represent other characters in another language. To overcome above shortcoming, the unicode system was developed where each character is represented by 2 bytes. As Java was developed for multilingual languages it adopted the unicode system.
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:
DrJava using a different font (PT Sans 12) on Linux:
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With