Connecting arrays question

This may be a silly question although I could see no other way of doing it. If there is a more simple way then please let me know.

Thank you anyone

/**

* Complete the program so that a new array twice is constructed.

* Now copy values from val to twice, but make the values in twice

* double what they are in val.

*/

class ArrayCopy

{

publicvoid process ( String[] argStrings )

{

int[] val ={13, -4, 82, 17};

int[] twice ={(val[0]*2), (val[1]*2), (val[2]*2), (val[3]*2)};//This used to be blank

System.out.println("Original Array: "

+ val[0] +

" " + val[1] +

" " + val[2] +

" " + val[3] );

// Put values in twice that are twice the

// corresponding values in val.

System.out.println("New Array: "

+ twice[0] +

" " + twice[1] +

" " + twice[2] +

" " + twice[3] );

}

}

[1645 byte] By [John4938a] at [2007-10-2 10:15:29]
# 1

try this

public class ArrayCopy {

public void process ( String[] argStrings )

{

int[] val = {13, -4, 82, 17};

int[] twice = new int[val.length];

for (int i = 0; i < val.length; i++) {

twice[i]=2*val[i];

System.out.println("Original Array: "+val[i]);

System.out.println("New Array: "+twice[i]);

}

}

}

brainydextera at 2007-7-13 1:39:58 > top of Java-index,Java Essentials,Java Programming...
# 2
Ok this helps, thanks. I will try and use this approach on the other programs I have like this.
John4938a at 2007-7-13 1:39:58 > top of Java-index,Java Essentials,Java Programming...
# 3
yr Welcome :)
brainydextera at 2007-7-13 1:39:58 > top of Java-index,Java Essentials,Java Programming...