可以使用 StringBuilderreverse() 方法来实现字符串反转,然后将结果输出。以下是一个示例程序:

public class ReverseString {
    public static void main(String[] args) {
        String str = 'Hello, world!';
        
        StringBuilder sb = new StringBuilder(str);
        sb.reverse();
        
        System.out.println(sb.toString());
    }
}

输出结果为:!dlrow ,olleH

Java 字符串反转:使用 StringBuilder 实现

原文地址: https://www.cveoy.top/t/topic/ov6e 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录