Iam trying to split a array of 5163 elements into 128 arrays, each array should not contains more than +/- 1 element of the average.
5163 / 128 = 40,33, rounded = 40. 5163 % 128 = 43, that indicates that 43 of 128 arrays should contain 1 more than the average.
How can I write this in code ?
String [] words; // Contains 5163 words
for(... .. .. .) {
....
}
You would need a collection to hold all of the arrays in, perform the division of elements in concordance with your constraints, then return the collection.
I would say that some number of arrays (some random 44 arrays, perhaps) would be getting an extra element in them after the division is done.