This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Get Down, Get Funky
Posted by Matt Gerrans on January 24, 2002 at 4:49 PM
> I just answered the very same question a few posts down! Do you all go to the same school or something?!
Here, if everybody in the class turns in this same code, the teach will probably not notice:
public class Reverser
public static void main( String  args )
String s = "able I was ere i saw elba";
if( args.length > 0 )
StringBuffer buffyTheVampireSlayer = new StringBuffer();
for( int i = 0; i < args.length; i++ )
if( i > 0 )
s = buffyTheVampireSlayer.toString();
System.out.println( "\"" + s + "\" reversed is \"" + reverse(s) + "\"" );
static String reverse( String s )
StringBuffer buffy = new StringBuffer();
for( int i = s.length()-1; i >= 0; i-- )
buffy.append( s.charAt(i) ); // Yee-haw! Used charAt()!
- Oops! Matt Gerrans January 24, 2002 at 4:56 PM