문자열 거꾸로 출력하기

StringBuffer의 reverse() 함수를 이용하면 쉽게 문자열을 순서를 뒤집어 출력할 수 있다.


1
2
3
4
5
6
7
8
9
10
11
public class Main {
    public static void main(String[] args) {
        String str = "Hello, world!";
        //Hello, world!
        System.out.println(str);
        StringBuffer strb = new StringBuffer(str);
        //!dlrow ,olleH
        System.out.println(strb.reverse().toString());
    }
}
 
cs
Share