Issue
val generatedArray = IntArray(10) { i -> i + 1 }
generatedArray
:
[1,2,3,4,5,6,7,8,9,10]
I want the array to start with 0
[0,1,2,3,4,5,6,7,8,9]
Solution
First, if you start with zero and want to go to the Nth number, your array would have to be of size N + 1.
Second, this would be pretty simple -
val generatedArray = IntArray(11) { i -> i }
This would generate the requested array - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Answered By - alonkh2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.