[mv-0-to-end-array] changes for comments

This commit is contained in:
Kai.Yuan 2024-02-04 19:24:20 +01:00
parent e8b27416d7
commit 7b115b3a26
1 changed files with 3 additions and 4 deletions

View File

@ -7,11 +7,11 @@ import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class MoveZeroesToTheEndOfAnArrayUnitTest { public class MoveZeroesToTheEndOfAnArrayUnitTest {
static final int[] EXPECTED = new int[] { 1, 2, 3, 4, 0, 0 }; private static final int[] EXPECTED = new int[] { 42, 2, 3, 4, 0, 0 };
@Test @Test
void whenCreatingANewArrayAndCopyingValues_thenGetTheExpectedResult() { void whenCreatingANewArrayAndCopyingValues_thenGetTheExpectedResult() {
int[] array = new int[] { 1, 2, 0, 3, 4, 0 }; int[] array = new int[] { 42, 2, 0, 3, 4, 0 };
int[] result = new int[array.length]; int[] result = new int[array.length];
int idx = 0; int idx = 0;
for (int n : array) { for (int n : array) {
@ -24,13 +24,12 @@ public class MoveZeroesToTheEndOfAnArrayUnitTest {
@Test @Test
void whenMovingZeroInTheOriginalArray_thenGetTheExpectedResult() { void whenMovingZeroInTheOriginalArray_thenGetTheExpectedResult() {
int[] array = new int[] { 1, 2, 0, 3, 4, 0 }; int[] array = new int[] { 42, 2, 0, 3, 4, 0 };
int idx = 0; int idx = 0;
for (int n : array) { for (int n : array) {
if (n != 0) { if (n != 0) {
array[idx++] = n; array[idx++] = n;
} }
System.out.println(Arrays.toString(array));
} }
while (idx < array.length) { while (idx < array.length) {
array[idx++] = 0; array[idx++] = 0;