I\'m suppose to do this....... to do a substitute array of the size of my origin
ID: 3533453 • Letter: I
Question
I'm suppose to do this.......
to do a substitute array of the size of my original array,
then I have to copy all of my elements from my original array.
then by doing a FOR LOOP for every index in my substitute array(such as m) I have to generate a random position within my substitute array(such as randposition) and then swap the element at index "m" with the element at index "randposition"
then return my substitute array.
ok if I have Word as my original array of 26 elements and I have Sub as my temporary array
do I do:
array Sub = new Word[26];
for(int i = 0; i<newWord.length; i++;)
for(j = 0, j < newWord.length [i ] j++)
{
Sub[i] [j] = newWord [i] [j];
}
return Sub;
it doesn't seem right
Explanation / Answer
int k=Word.length;
int sub[]=new int[k];
// To copy to substitute string;
for(int i = 0; i<k; i++;)
{
sub[i] = Word [i];
}
Random randomGenerator = new Random();
//for swaping random value
for(int i = 0; i<k; i++)
{
temp=sub[i];
sub[i]=sub[randomInt];
sub[randomInt]=temp;
}
// for displaying use this
for( i = 0; i<k; i++)
{
{
System.out.prinltn(sub[i]);
}
}