Skip to content

Instantly share code, notes, and snippets.

@els-pnw
Created August 30, 2012 16:52
Show Gist options
  • Save els-pnw/3533047 to your computer and use it in GitHub Desktop.
Save els-pnw/3533047 to your computer and use it in GitHub Desktop.
/**
*
* @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