Swapping Elements of an Array

stupid questionhow could i swap the element of an array where array swaps with array[k]
[108 byte] By [Blitz@CSUa] at [2007-11-26 16:22:16]
# 1
Did you mean to write "where array[i] swaps with array[k]" ?Anyway, a hint: can you write code that swaps the values of variables x and y? If so, I bet you can write code that swaps the values of array[i] and array[k].Message was edited by: DrLaszloJamf
DrLaszloJamfa at 2007-7-8 22:46:03 > top of Java-index,Java Essentials,New To Java...
# 2

You can do a simple method depending on your need to either loop

y=1;

for(x=0;x<otherArray.length();x++)

{

firstArray[x]=otherArray[y];

}

if you are trying to swap all values from one array to another

or

for(x=0;x<otherArray.length();x++)

{

tempArray[x]=firstArray[x];

firstArray[x]=secondArray[x];

secondArray[x]=tempArray[x];

}

if you want to swap same items in each array, at least as a really basic way of doing it. You may need alterations if the arrays are different lengths.>

JoshRa at 2007-7-8 22:46:03 > top of Java-index,Java Essentials,New To Java...