Created
January 10, 2013 13:23
-
-
Save madan712/4502000 to your computer and use it in GitHub Desktop.
Java function to reverse a String
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 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