Created
August 22, 2015 07:23
-
-
Save reza-ryte-club/7b13be42ae3855736c39 to your computer and use it in GitHub Desktop.
Reverse A String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringReverse { | |
public static String reverseString(String str){ | |
StringBuilder dest = new StringBuilder(str.length()); | |
for(int i = str.length()-1;i>=0;i--){ | |
dest.append(str.charAt(i)); | |
} | |
return dest.toString(); | |
} | |
public static void main(String[] args) { | |
System.out.println("reverse string"); | |
String word = "Hello world"; | |
System.out.println(reverseString(word)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment