Skip to content

Instantly share code, notes, and snippets.

@madan712
Created January 10, 2013 13:23
Show Gist options
  • Save madan712/4502000 to your computer and use it in GitHub Desktop.
Save madan712/4502000 to your computer and use it in GitHub Desktop.
Java function to reverse a String
public class Str {
public static String reverseit(String orig) {
String reverseStr = "";
for (int i = orig.length() - 1; i >= 0; i--)
reverseStr = reverseStr + orig.charAt(i);
return reverseStr;
}
public static void main(String[] args) {
String strToReverse = "Hello World";
System.out.println("Reverse of '" + strToReverse + "' is '"
+ Str.reverseit(strToReverse) + "'");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment