Answer the question
In order to leave comments, you need to log in
How to wrap a row in a 2D array if the number of elements is greater than a certain number?
It is necessary to display a two-dimensional array with a different number of characters in each line, if the number of characters in a line is more than 20, transfer the remainder to a new line. Let 's say
[
[Hello, me],
[my name is Ivan, Ivanovich, Ivanov]
]
So that the word "Ivanov" is already on a new line.
Answer the question
In order to leave comments, you need to log in
It does not matter that the array is two-dimensional. In fact, you need to output one array of hyphenated characters. Only it is necessary to solve this problem separately for each row of a two-dimensional array.
The simplest solution is to print '\n' in the character output loop if the current character is the 20th, 40th, etc. For example, you can check (i+1) % 20 == 0
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question