Why the specified invalid character constant
Because of this part:
'\' '
This is an attempt to specify a character literal, which is actually two characters (apostrophe and space). A literal character must be exactly one character.
If you want to specify an "apostrophe space", you should use a string literal instead - at this point the apostrophe should not be escaped:
"' "
All your statement will be better:
return (int) (feetPart) + "' " + inchesPart + "''";
Or use " instead '' for inches:
return (int) feetPart + "' " + inchesPart + "\"";
Please note that itโs not even clear to me that the source code would do what you would like it to compile, since I suspect that it would perform integer arithmetic on feetPart and the symbol ...
Your code would be fine in Javascript because both single quotes and double quotes are used for string literals.
source share