문제풀기/코드업 문제풀기(Java)
1001 ~ 1007 풀기 (Java로 풀기)
project100
2023. 2. 9. 23:28
1. Hello 출력
public class Main {
public static void main(String[] args) {
System.out.println("Hello");
}
}
2. Hello World 출력
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
3. Hello
World 출력
public class Main {
public static void main(String[] args) {
System.out.println("Hello \n World");
}
}
띄어쓰기 표시하는 방법 \n
이스케이프 문자에 대해서 알아두기
4. 'Hello' 출력
public class Main {
public static void main(String[] args) {
System.out.println("'Hello'");
}
}
" " 안에 ' '를 써도 그대로 출력된다.
5. "Hello World" 출력
public class Main {
public static void main(String[] args) {
System.out.println("\"Hello World\"");
}
}
" "를 쓰려면 \를 적절하게 배치해야 한다.
시작부분과 끝나는 부분 모두 " 가 출력될 부분 앞에 \ 를 써야 한다. \"Hello World\"
6. "!@#$%^&*()" 출력
public class Main {
public static void main(String[] atgs) {
System.out.println("\"!@#$%^&*()\"");
}
}
7. "C:\Download\hello.cpp" 출력
public class Main{
public static void main(String[] args) {
System.out.println("\"C:\\Download\\hello.cpp\"");
}
}
먼저 시작부분과 끝나는 부분 모두 " 가 출력될 부분 앞에 \ 를 쓴다.
\"C:\Download\hello.cpp\" 출력할 " " 앞에 \ 2개 먼저 작성
\를 표시한 부분 앞에 한 번 더 써준다.
\"C:\\Download\\hello.cpp\" 출력할 \ 앞에 \ 2개 작성