Issue
I’m looking for what I think is a very simple bit of code but I’m struggling to figure it out so let me try and explain as clearly as I can
Basically, I have a string let’s say for example string Tweet =(“Happy Birthday”)
And I have int called width which let’s just say is equal to 3
How would I make it so the string prints only the amount of characters that squeal to the int width per line so it would look like this
Hap
Py
Bir
Thd
Ay
Sorry again for the poor formatting I don’t know how better to explain it
Solution
public static void printLimit(String str, int lineLength) {
for (int i = 0; i < str.length(); i++) {
System.out.print(str.charAt(i));
if ((i + 1) % lineLength == 0)
System.out.println();
}
}
Answered By - oleg.cherednik