Side Navigation

X

Reverse a String

Write a method that reverses a string.
For example, ‘bestOnlineLearning.net’ becomes ‘ten.gninraeLenilnOtse’.
public class BestOnlineLearning {

    public static String reverseString(String str){
       String rStr = "";
       for(int i = str.length()-1; i>=0; i--){
           rStr = rStr + str.charAt(i);
       }
       System.out.println(rStr);
       return rStr;
    }

    public static void main(String[] args) {
        String str = "bestOnlineLearning.net";
        reverseString(str);
    }
}

 

You May Also Like

Comments

Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>