Question: JAVA Array Question. How to increment an array by -1 in one single loop? For example: int[] arr = [1, 2, 3, 4]; for(i=0; i

JAVA Array Question.

How to increment an array by -1 in one single loop? For example:

int[] arr = [1, 2, 3, 4];

for(i=0; i

//do something

}

and at the end of the first loop i want arr to be: arr = [0, 1, 3, 4], and then when i=2, arr= [ 0, 0, 2, 4], etc.

I tried this:

for(i=0; i

arr--;

//do something

}

but it gives me: arr = [0, 2, 3, 4], [0, 1, 3, 4], etc.. only one element at a time.

Please help me with this data structure. Thumbs up will be given for correct answer! thank u

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!