Skip to content

Instantly share code, notes, and snippets.

@devsamuelv
Created May 3, 2025 03:15
Show Gist options
  • Save devsamuelv/8d3a69549d210d50dc9edef2882306dd to your computer and use it in GitHub Desktop.
Save devsamuelv/8d3a69549d210d50dc9edef2882306dd to your computer and use it in GitHub Desktop.
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