So I’m making a basic GUI with the NetBeans IDE (in Java), and I want to make a button with a √ sign in it. It didn’t let me copypaste it in, so I tried using its ASCII code – char sqrt = (char) 251. Instead of the square root sign, however, it gave me “û”, and I have no idea why. Can someone please explain why this is happening, as well as offer an idea as to how I should go about this?
So I’m making a basic GUI with the NetBeans IDE (in Java), and I
Share
Java characters are Unicode, not ASCII. Unicode codepoint 251 (U+00FB) is “Latin Small Letter U with Circumflex”. To make input of various Unicode characters using a character set with only the basic ASCII symbols, Java provides a way to input Unicode characters using a literal format. So, you can do this:
since U+221A is the Unicode codepoint for the square root symbol.
This \uXXXX format can also be used in String literals:
If you print that String, you will see