Forums Register Login

Copying array into another array

+Pie Number of slices to send: Send
 


/* Program name: Array02.java
* Author name: Place your name here
* Description:
*/

// Class name
public class Array02 {
// Main function
public static void main ( String[] args ) {
int items[] = {4,5,0,7};
int hold[] = {6,2,1,8,5};
System.out.println(items,0,hold,0,items.length);
}
}


I wrote a program based on my study guide that copy a data from items[0] and paste it into hold[0] which will replace the data in hold[0]
But it gaves an error during the compilation. Can anyone help me to fix this thanks.
+Pie Number of slices to send: Send
I don't see it anyway that you are trying to copy and paste. Besides, println method doesn't support what you trying to do anyway. This should give you a basic example.
+Pie Number of slices to send: Send
Will you please post the exact error message that you recieve? Copy and paste it word for word so we don't have to guess what the problem is. Also, as Adrian mentioned, the code you posted doesn't even match the description you gave. I don't see any code that is trying to copy from one array to another. The System.out.println() method prints text to the standard output (typically the monitor or console). To copy from one array element to another, you should use something like this:
hold[0] = items[0];
I still think you need to reword your question, or explain what you mean a little better. I hope we can help you out once you do this. And remember to post the exact compiler error that you get!
Layne
+Pie Number of slices to send: Send
sorry my english is poor. let me explain again, the method above is a method that copy the data in an array named items[0] which is 10 and stored it into another array named hold[0] which would overwrite the value of 20. thus the value in hold[0] became 10.
my reference book doesnt explain much. that is all it explain. i'm a bit confused so i need help from you guys.
here's the output:
+Pie Number of slices to send: Send
Ayukawa-
I think this is what you are trying to do

[ March 06, 2004: Message edited by: Vicken Karaoghlanian ]
+Pie Number of slices to send: Send
 


hold[0] = items[0];



System.arraycopy(items,0,hold,0,items.length);


Yes this is what i want! yay thanks a lot guys!!
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 701 times.
Similar Threads
in main
Arranging members of array in a ascending order?
JOptionPane and ArraySize not known
Arrays: Calling input from other methods and classes
Sorting arrays
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:50:59.