Question:
Simple JAVA coding..problem..?
Sabirk88
2007-10-07 15:59:08 UTC
How to solve this coding problem? I got this message "Exception in thread.. TQ.

public class A
{
public static void main(String [] args)
{
System.out.println("");
double Susun1[] = { 2.0, 9.0, 8.0, 9.0, 1.0, 1.0 };
double Susun2[] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
String output="";
//#1
output = "Before Modified \n";
output = output + "------------------------------ \n";
output = output + "Susun1 \t Susun2 Susun1+Susun2 \n";
System.out.println(output);
for(int p=0; p System.out.println(Susun1[p] +" \t "+ Susun2[p] +" \t "+ (Susun1[p]+Susun2[p]) );
//#2
output = "\nAfter Modified \n";
output = output + "------------------------------ \n";
output = output + "Susun1 \t Susun2 Susun1+Susun2 \n";
System.out.println(output);
//Copying...
System.arraycopy( Susun2 , 1 , Susun1 , 1, Susun1.length);
for(int p=0; p System.out.println(Susun1[p] +" \t "+ Susun2[p] +" \t "+ (Susun1[p]+Susun2[p]) );}}
Three answers:
Bob R
2007-10-10 07:04:50 UTC
Your source and destination start points in the System.arraycopy() call start at 1 instead of 0.
rice kid
2007-10-07 17:07:31 UTC
ok not sure about this, but here goes.

the System.arraycopy function takes 5 arguments: src, srcposition, dest, destposition, length.



your length was sunsun1.length, so I'm assuming you want to copy your whole array. So if that's the case you specified that the positions start at element 1 of each array, which is in "array language", the second element in the array.



Try switching to position 0 for both the src and the dest arrays



I haven't tried it out, but sounds like the only thing logical from looking at the code.



Hope that helps.
gitter1226
2007-10-07 16:07:53 UTC
You could make it considerably easier for someone to help you if you give us the exception.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...