import java.util.Scanner;public class ScannerDemo12 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个字符串");String str = sc.next();//链式编程StringBuilder sb=new StringBuilder();sb.append(str);//字符串反转sb.reverse();System.out.println(sb);} }
import java.util.Scanner;public class ScannerDemo12 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个字符串");String str = sc.next();//字符串反转//链式编程 先添加str 在反转, 接着在用tostring变回字符串 在赋值给一个新变量String result= new StringBuilder().append(str).reverse().toString();System.out.println(result);} }