❔ Array confusion..
I'm trying to figure out how to choose a set amount of values from an array without using all the values in it at once.
for example if I have
int[] X = new int[] { 1, 2, 3, 4, 5, 6, 7};
and I wanted to get the sum of only the first 5 values in the array, how do I do that?
hopefully I explained it well enough cuz I wasn't able to put my problem into the correct words and find the answer through google lol...
7 Replies
Well, you'd acccess the first 5 items in the array and sum them up?
yeah but I'm not quite sure how to write the code in a way that selects for example the first 5 but not the 6th onwards
look into loops
Or range operators
Angius
REPL Result: Success
Result: int[]
Compile: 466.819ms | Execution: 57.355ms | React with ❌ to remove this embed.
This is exactly what I was looking for ty lol ❤️
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.