I am currently working on a program that manipulates strings passed in as parameters using strictly recursion. Right now, I am stuck trying to print the word out vertically.
public static void printVertical(String str) {
if (str == null || str.equals("")) {
System.out.print("");
} else {
char nextLetter = printVertical(str.substring(1));
System.out.println(nextLetter);
printVertical(str);
}
}
This is the code for the method to print words vertically; the error I get when I try testing this method reads
java.lang.StringIndexOutOfBoundsException: String index out of range: 100
at java.lang.String.charAt(Unknown Source)
at StringRecursion.printVertical(StringRecursion.java:97)
I think it has something to do with the fact that my method returns void (something I'm not allowed to change due to assignment restrictions), and not char. Any help in guiding me in the right direction would be greatly appreciated.