题目描述
写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串。例如:
输入描述
输入N个字符
输出描述
输出该字符串反转后的字符串
输入例子
abcd
输出例子
dcba
算法实现
import java.util.Scanner;/** * All Rights Reserved !!! */public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String input = scanner.nextLine(); System.out.println(stringReverse(input)); } scanner.close(); } private static String stringReverse(String input) { StringBuilder builder = new StringBuilder(input.length()); for (int i = input.length() - 1; i >= 0; i--) { builder.append(input.charAt(i)); } return builder.toString(); }}