문자열 뒤집기
package _2;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String string =sc.next();
String st = "";
for(int i=0 ; i<string.length(); i++) st+=string.charAt(string.length()-1-i);
System.out.print(st);
}
}
reverse 메소드 이용
package _2;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String string =sc.next();
System.out.print(reverseStr(string));
}
public static String reverseStr(String s) {
return (new StringBuffer(s)).reverse().toString();
}
}