Created
August 30, 2012 16:52
-
-
Save els-pnw/3533047 to your computer and use it in GitHub Desktop.
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
/** | |
* | |
* @author Eric Sammons | |
* @course x436.2 | |
* @assignment Module 3 | |
* | |
*/ | |
public class ReverseString { | |
/** | |
* Will reverse a string. | |
* @param s | |
*/ | |
static String reverse(String s) { | |
if (s == null || s.length() == 0) { | |
return s; | |
} | |
return reverse(s.substring(1, s.length())) + | |
s.substring(0,1); | |
} | |
/** | |
* Requires one arg to be passed, will exist if not | |
* not satisfied. Arg passed will be reversed. | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
if (args.length != 1) { | |
System.err.println("You must pass at least one argument"); | |
System.exit(1); | |
} | |
String reverseMe = args[0]; | |
System.out.println("Your string reversed: " + reverse(reverseMe)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment