Created
January 4, 2012 19:10
-
-
Save mahmoudhossam/1561515 to your computer and use it in GitHub Desktop.
How to reverse strings in Java.
This file contains hidden or 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 Reverse { | |
public static void main(String[] args) { | |
System.out.println(reverse("Mahmoud")); | |
} | |
public static String reverse(String src) { | |
StringBuilder builder = new StringBuilder(); | |
for(int i = src.length() - 1; i >= 0; i--) { | |
builder.append(src.charAt(i)); | |
} | |
return builder.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment