How to subtract the values in array with other values and put results back to array in java? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How to subtract the values in array with other values and put results back to array in java?

8th Dec 2017, 5:52 AM
Shiki
Shiki - avatar
2 ответов
+ 2
I'm not exactly sure if I'm ok interpreting your question.. but i will try to help with the following code: for(int i = 0; i < array.length; i++) { array[i] -= valueToSubstract; } You can use the same way (index access) to substract one element to another separated by a fixed quantity like this: array[i] -= array[i + 1]; (take care about logic errors e.g. a chain of substractions you didn't want to do, control this with step or for's increment section, and not to get out of bounds, control last with the for's condition section) Excuse my english, i hope that helps you! bye! :)
8th Dec 2017, 6:07 AM
Mauro Bastasini
Mauro Bastasini - avatar
+ 2
Thanks you so much😊😊
8th Dec 2017, 6:29 AM
Shiki
Shiki - avatar