Java - Write code to reverse a string by appending its char element backward to a StringBuilder

Requirements

Write code to reverse a string by appending its char element backward to a StringBuilder

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String input = "book2s.com";
        System.out.println(reverse(input));
    }//ww  w .j  a v a  2 s . c  o  m

    public static String reverse(String input) {
        StringBuilder result = new StringBuilder();
        for (int i = input.length() - 1; i >= 0; i--) {
            result.append(input.charAt(i));
        }
        return result.toString();
    }
}

Related Quiz