builder.setCharAt(i, Character.toUpperCase(split[i].charAt(j)));
public static String getJustifiedText(String text, int maxChars) {
String[] words = text.split(" "); // 35
StringBuilder justifiedText = new StringBuilder();
int currentChars = 0;
for (String word : words) {
currentChars += word.length() + 1;
if (currentChars > maxChars) {
justifiedText.append("\n");
currentChars = word.length() + 1;
}
justifiedText.append(word).append(" ");
}
return justifiedText.toString().trim();
}
ошибка такая:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
at java.base/java.lang.String.checkIndex(String.java:4570)
at java.base/java.lang.AbstractStringBuilder.setCharAt(AbstractStringBuilder.java:536)
at java.base/java.lang.StringBuilder.setCharAt(StringBuilder.java:91)
at chapter10.variantC.task4.Main.main(Main.java:26)