▶ 문제
https://www.acmicpc.net/problem/25083
25083번: 새싹
아래 예제와 같이 새싹을 출력하시오.
www.acmicpc.net
▶ 설명
특수기호 큰따움표 " 와 역슬래시 \ 를 단독으로 입력하게 제대로 하기 위해서는 어떻게 해야 할지에 대한 문제이다..
escape 문자에 대한 이해.
▶ 문제 풀이
🌱 풀이1. BufferedWriter 사용
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(" ,r'\"7");
bw.newLine();
bw.write("r`-_ ,' ,/");
bw.newLine();
bw.write(" \\. \". L_r'");
bw.newLine();
bw.write(" `~\\/");
bw.newLine();
bw.write(" |");
bw.newLine();
bw.write(" |");
bw.newLine();
bw.flush();
bw.close();
}
}
첫 줄 ,r'"7 에서 " 를 입력할 때 " 앞에 \ 를 추가하여 \" 라고 해야 한다.
마찬가지로 ' 와 \를 출력하고자 할 땐 \를 앞에 추가해주어야 한다.
줄바꿈과 탭을 하려고 할 때 \n, \t을 입력하는 것과 비슷한 형태라고 보면 된다.
\를 추가하여 어떠한 용도를 갖는 문자를 escape character 라고 한다.
Escape Characters |
Description | 출력물 |
\t | It is used to insert a tab in the text at this point. | 탭 |
\' | It is used to insert a single quote character in the text at this point. | ' |
\" | It is used to insert a double quote character in the text at this point. | " |
\\ | It is used to insert a backslash character in the text at this point. | \ |
\n | It is used to insert a new line in the text at this point. | 개행 |
출처 javatpoint
▶ Log
728x90
반응형
'백준 알고리즘 > 입출력' 카테고리의 다른 글
백준 10869번 :: 사칙연산 (0) | 2022.05.14 |
---|---|
백준 1001번 :: A-B (0) | 2022.05.14 |
백준 10171 :: 고양이 (0) | 2022.05.13 |
백준 10718 :: We love kriii (0) | 2022.05.13 |
백준 2557번 :: Hello World (0) | 2022.05.12 |