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.

Strings in Java, I really need help.?

I need to think up of a code that would take a word and switch its first and second halves. If you have a word like "helpmeee" it would need to be switched to "meeehelp". I cannot think of anything that would work other than by using substrings...however, this code needs to work for strings of any length, so substrings would not help me out.

The exact lab activity is as follows:

In the following code segment, d and e are Strings. The number of characters in d is an even number greater than zero. Write code that stores in e the String formed by switching the two halves of d. For example, if d is "pushdown", then e should evaluate to "downpush".

1 Answer

Relevance
  • Silent
    Lv 7
    1 decade ago
    Favorite Answer

    You're certainly going to need to use substrings to do this. Why wouldn't they work for Strings of any length?

    Here's a hint: you can get the length of a String by calling its length() method. You can then do some very simple math on that number to find out how long the first half of the String is.

Still have questions? Get your answers by asking now.