user1792995
user1792995

Reputation: 75

Java - All characters have a numerical value?

I am doing some homework for my first programming class, yay! :)

However, one of the programs I need to do, sorts any set of characters that a user inputs. It can be any character (& or $ or 5 or F).

So far I have done this with only letters:

if (a.compareTo(b)<=0 && a.compareTo(c)<=0)

or for numbers:

if (a<=b && a<=c)

But does java apply a numerical value to all the characters, or how does java sort characters like $ and @?

(I have found similar questions, but they were all in C++, I'm too much of a newbie to understand the similarities, I tried though)

Thanks for the help.

Upvotes: 2

Views: 4260

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726559

All characters do have numeric values assigned according to their corresponding codepoints in UNICODE (the initial 127 UNICODE code points match ASCII codes).

Specifically, the numeric code of the "at" sign @ is 64, and the code of the dollar sign '$' is 36.

Also note that digits are characters as well, so they too have numeric values (48 through 57).

Upvotes: 7

Related Questions