Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Java--recursive static method Question?

Consider the following recursive static method:

public static String scramble( String s )

{

int n = s.length();

if ( n < 2 )

return s;

if ( n % 2 == 0 )

return s.substring( 0, 1 ) + scramble ( s.substring( 1 ) );

else

return scramble( s.substring( 1 ) ) + s.substring( 0, 1 );

}

What is the output when the statement:

System.out.println( scramble( "all shook up" ) );

is executed?

I believe that the result would be "alsokup oh l"

Since I don't have Java installed on my laptop, there's no way for me to make sure of the result.

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    You're correct, I tried your program and it displays "alsokup oh l".

    Good work, happy learning :)

  • ?
    Lv 7
    1 decade ago

    Hey, xxabmxx

    It looks like you've been getting some good answers in this forum, and everybody's happy to help. That's what Yahoo! Answers is all about!

    But I hope you don't mind if I make a suggestion:

    You seem to be doing well in your Java class -- your code has been pretty much correct so far. Most of your questions have simply been to ask for verification, because you don't have Java installed on your laptop.

    So I think it will be easier and faster for you to complete these projects if you actually do install the JDK, along with a Java IDE. It's free, and there are many good IDEs out there.

    For example, you might consider NetBeans or Eclipse (check out the links below). But there are other good options, too.

    As I say, they're free and I can't think of any reason not to have them installed on your machine! Good luck.

Still have questions? Get your answers by asking now.