Java - Write code to do string Reverse using for loop

Requirements

Write code to do string Reverse using for loop

Demo

//package com.book2s;

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

    public static String stringReverse(String str) {
        char[] reversed = str.toCharArray();
        String reversedString = "";
        for (int i = reversed.length - 1; i >= 0; i--) {
            reversedString += reversed[i];
        }
        return reversedString;
    }
}

Related Example