Created
May 3, 2025 03:15
-
-
Save devsamuelv/8d3a69549d210d50dc9edef2882306dd 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
import java.util.Random; | |
import java.util.Scanner; | |
public class App { | |
public static void main(String[] args) throws Exception { | |
String[] exampleText = "momdad".split(""); | |
System.out.println(rebuildString(exampleText)); | |
reverseText(exampleText, 0); | |
System.out.println(rebuildString(exampleText)); | |
} | |
public static String rebuildString(String... oldStrings) { | |
String s = ""; | |
for (String f : oldStrings) { | |
s += f; | |
} | |
return s; | |
} | |
public static void reverseText(String[] text, int currentIndex) { | |
int fullLength = text.length - 1; | |
int endIndex = fullLength - currentIndex; | |
if (endIndex - currentIndex > 0) { | |
String e = text[endIndex]; | |
String f = text[currentIndex]; | |
text[endIndex] = f; | |
text[currentIndex] = e; | |
reverseText(text, currentIndex + 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment