+ 1
Why my code isnt working (20 lines) help please
4 ответов
+ 4
Your arrays are only swaped locally inside the function.
+ 3
import java.util.Arrays;
public class Test {
static int[] one, two; //added variables for return
public static void main(String[] args) {
int[] one = {1, 2, 3}; // some two local arrays
int[] two = {4, 5, 6};
swap(one, two);
System.out.println(Arrays.toString(Test.one)); // print returned object
System.out.println(Arrays.toString(Test.two)); // added Test.
}
public static void swap(int[] array1, int[] array2) {
// one = array2; two = array1;
int[] temp = array1;
array1 = array2;
array2 = temp;
one = array1; // added return object with two variables
two = array2;
}
}
0
thanks both, I've done this way
https://code.sololearn.com/cSBH8IkG14bQ/?ref=app
0
ok, good for small arrays,
but array two can't be shorter than array one