输入:abcd
输出:dcba
面试考过
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
StringBuffer s=new StringBuffer(sc.nextLine());
System.out.print(s.reverse());
}
sc.close();
}}
本文介绍了一种使用Java语言实现字符串反转的方法。通过读取用户输入的字符串并利用StringBuffer类的reverse()方法来完成字符串的反转操作。此代码示例适用于初学者了解字符串操作的基本技巧。
602

被折叠的 条评论
为什么被折叠?



