print(" $$$$$$\ $$$$$\ $$$$$$\ $$\ $$\ "+newline+
"$$ __$$\ \__$$ | $$ __$$\ $$ | $$ |"+newline+
"$$ / $$ | $$ | $$ / $$ | \$$\ $$ |"+newline+
"$$$$$$$$ | $$ | $$$$$$$$ | \$$$$ /"+newline+
"$$ __$$ | $$\ $$ | $$ __$$ | $$ $$< "+newline+
"$$ | $$ | $$ | $$ | $$ | $$ | $$ /\$$\"+newline+
"$$ | $$ | \$$$$$$ | $$ | $$ | $$ / $$ |"+newline+
"\__| \__| \______/ \__| \__| \__| \__|"+newline);
Hi all ! I am just trying to add ascii art to my games gui, and I get this error? How do I resolve this?
The backslash character \
is an escape character in Java. The compiler thinks that you are attempting to escape the next character, and \_
is an invalid escape sequence. You need to escape the backslash itself. Replace every \
with \\
.
to print a \
you need to specify \\
in your string literals.
you don't need to type them all manually. your IDE might have a cool feature witch lets you escape all chars that need to be escaped when pasting to a string literal.
for eclipse it is under:
Window > preferences > java > Editor > typing
then check Escape text when pasting to a string literal
You need to double up every backslash, i.e. replace each \
with \\
.
The backslash character has special meaning inside Java string literals. It denotes the start of so-called escape sequences. For example, \n
stands for "new line".
The escape sequence \\
stands for a single backslash character.
escape the backslashes, basically replace all your backslashes with \\
All your backslashes need to be escaped with double backslashes:
e.g.
print(" $$$$$\\");