Skip to content

Tag: for-loop

Add/Subtract/etc element by the next element in an array

I have an array with [25, -6, 14, 7, 100]. The expected output is Basically, the next element is subtracted/added to the current element when looping. That sum and product is easy as I only need to do The problem is that when I do difference -= i, it gives me -108, which is wrong. And when there is only

Separate List in Java

I need help on separating List. I am really new to this I have a code that results to this [[a, b, c, d, e], f] setOfLetters() is from a query My question is how can I make my result like this? [a, b, c, d, e, f] Is it by using for loop? Or anything you can suggest. Thanks

java for loop early termination

This is the first half of my java program- to input certain values. I noticed that the first ‘for loop’which takes in values of the answer key is getting terminated after 2 or 3 iterations instead of the expected 5, and I have, so far, had no luck in figuring out why. Any help would be appreciated…