package day01;
import java.util.Scanner;
//字符串反转练习
public class StringBuilderTest3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串");
String s = sc.nextLine();
//写方法实现反转
String result = myReverse(s);
System.out.println("result:"+result);
}
public static String myReverse(String s){
//要实现反转想要调用revese方法就得先将String类型转换成StringBuilder类型然后写方法最后在转为String类型
StringBuilder sb = new StringBuilder(s);
sb.reverse();
String result = sb.toString();
return result;
}
}
运行结果