I'm fairly new to Java, so please be gentle.
This appears to be a common question, but I still seem to be unable to find the answer I'm looking for.
I'm writing a console app that will take a string of characters and print them out on the screen but bigger. For example: "JAVA" would print as:
JJJJJ A V V A
J A A V V A A
J A A V V A A
J AAAAA V V AAAAA
J A A V V A A
J J A A V V A A
JJJ A A V A A
Nothing special there. The string gets broken down into characters, each character is then looked up in a large switch case, which then returns the bigger letter. After some wrapping is done where necessary, the big letters are glued together and printed.
That was too easy and since I like to make my life more challenging, I want to allow certain unicode characters, such as a black heart (❤) \u2674, (which is what the Windows character map claims it is, anyway). Basically, passing some kind of code into the parameter will be replaced internally within the strong and interpretted as a unicode character, for example: JAVA {HEART} might output (I know the heart is messed up, but it displays fine with a monospaced font):
JJJJJ A V V A ❤❤ ❤❤
J A A V V A A ❤❤❤❤❤❤
J A A V V A A ❤❤❤❤❤
J AAAAA V V AAAAA ❤❤❤❤
J A A V V A A ❤❤❤
J J A A V V A A ❤❤
JJJ A A V A A ❤
As far as I'm aware, the unicode should fit into a char (2 bytes) and should definitely fit into an int (4 bytes) so I did an experiment. Word on the street is that casting to an int will give you the character code.
String unicodeStr = "\u2674"; // Unicode for black heart.
System.out.println(unicodeStr.getBytes().length); // Only one byte, so should fit into a char, right?
char unicode = '\u2674'; // All good so far.
System.out.println((int)unicode); // Returns 9844. WTAF??
System.exit(-1); // Argh! Oh noez... Panic!
Obviously I'm misunderstanding something here, but I don't know what. Please could someone explain why I'm getting the wrong char code? I've tried using codePoints but obviously I don't know what I'm doing with that either. If anyone could please point me in the right direction, I'd be eternally grateful. The objective is to split the string into characters and translate each character into a big letter via a switch case.