Baekjun 10171, Cat (with.Java)
This is an article about Baekjun (with.Java) No.10171.
I want to solve the coding test problem, find out how to solve it differently from the retrospective of the problem I solved, and get to know.
Letβs get to the problem first.
Problem
Print out the cat as in the example below.
Input
None.
Output
It prints out a cat.
problem solving
class Main {
public static void main(String[] args) {
System.out.println("\\ /\\");
System.out.println(" ) ( ')");
System.out.println("( / )");
System.out.println(" \\(__)|");
}
}
Solution Description
β\β outputs . () outputs parentheses. | outputs a pipe.`
This code uses an escape sequence to output special characters, and each System.out.println statement is printed one line at a time.
I knew that solving the problem was possible only when I knew about the escape sequence.
What is Escape Sequence Escape sequences are used to represent characters with special meanings within strings. They are usually used to include control characters or special characters in strings. Escape sequences begin with a backslash (\
) and perform various functions depending on the characters that follow.
Key Escape Sequences
\\ : means the backslash (\) itself. \' : means lower quotation marks ('). \" : means double quotation marks ("). \n : Change Line (move to new line) \t : Tab characters (typically 4 or 8 spaces) \r : carriage return (go to the beginning of the line) \b : Backspace (delete old characters) \f : Form Feed (Divide pages) \uXXXX: Unicode character (XXXX is a 4-digit hexadecimal)
Conclusion
If the code contains double quotes (ββ) and reverse slashes (β') when expressing characters with special meanings, you can put one reverse slash before the character with special meanings.
Thank you!