If you are not sure which array is the shortest you could check it first, than after you find this out you can make a for loop
so that you always get the value from all three arrays with the lowest value of the weakest link... like so:
private static void doStackOverflow() {
String[] shortest = {"one", "two", "three", "four"};
String[] medium = {"a", "b", "c", "d", "e", "f"};
String[] longest = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
System.out.println(formatStory(shortest, medium, longest));
}
public static String formatStory(String[] shortest, String[] medium, String[] longest) {
int weakestLink = findWeakestLink(shortest.length, medium.length, longest.length);
String formattedStory = "";
for (int i = 0; i < weakestLink; i++) {
formattedStory += shortest[i] + " " + medium[i] + " " + longest[i] + " ";
}
return formattedStory;
}
private static int findWeakestLink(int shortest, int medium, int longest) {
int result = shortest + medium + longest;
if (shortest < result)
result = shortest;
if (medium < result)
result = medium;
if (longest < result)
result = longest;
return result;
}