Hmm, I dont think any of them do, maybe, ActionScript, or Fortan, but i know about every other language and they alls tart with the index of (0)
2006-09-02 13:20:17
·
answer #1
·
answered by Savarious 2
·
0⤊
0⤋
Wow, all the different reported solutions contain a good type of iterating and rewriting aspects one after the other. Java promises a miles more effective powerful and faster thanks to replica arrays, taking great element with regard to the contiguous memory allocation given to arrays. equipment.arraycopy() has similarities to a memcopy() call. right it really is an party: public type ArrayReplacementDemo { //only a helper thanks to fantastically print arrays public static void printArray(int[] array){ if(array.length > 0){ equipment.out.print(array[0]); } for (int n = a million; n < array.length; n++) { equipment.out.print(", " + array[n]); } equipment.out.println(); } public static void important(String[] args) { // I used a somewhat larger array to exhibit more effective int[] array1 = { a million, 2, -3, 4, -5, 6, 7 }; equipment.out.println("starting up with:"); printArray(array1); equipment.out.println(); for (int i = 0; i < array1.length; i++) { if (array1[i] < 0 && i < array1.length - a million) { //replica the relax again to same array, yet shifted actual equipment.arraycopy(array1, i+a million, array1, i+2, array1.length - i - 2); array1[i+a million] = 0; } //examine progression printArray(array1); } } } The output then appears like this: starting up with: a million, 2, -3, 4, -5, 6, 7 a million, 2, -3, 4, -5, 6, 7 a million, 2, -3, 4, -5, 6, 7 a million, 2, -3, 0, 4, -5, 6 a million, 2, -3, 0, 4, -5, 6 a million, 2, -3, 0, 4, -5, 6 a million, 2, -3, 0, 4, -5, 0 a million, 2, -3, 0, 4, -5, 0 basically as you unique, even as ever a adverse value is stumbled on, a 0 is inserted AFTER the adverse value and the the relax are pushed actual in the confines of the present array length.
2016-12-06 04:35:28
·
answer #2
·
answered by akana 4
·
0⤊
0⤋
Not many start the index at 1 anymore. Fortran is the one that comes to mind. Starting at 1 seems intuitive to us because we're used to starting at 1 when we count, but 0 matches the logic of how addressing works. Let's say that pointer P to an array indicates the address at which it starts. If we call the amount of storage each value of the array requires 1 unit (which may be 1 byte, 2 bytes, 4 bytes, whatever), then the first value is located at P, the second at P+1, and so forth.
2006-09-02 13:38:20
·
answer #3
·
answered by Fix My PC Mike 5
·
0⤊
0⤋