私はこの小さなプロジェクトに参加していて、コードの主要な問題を(運も結果もなしに)解決するのに20時間ほど費やしています。今、私は、copy()関数が正しく機能しないことが本当の問題であることに気付いたところです。
私は何が間違っているのですか?
これは私が特定の問題について作った例です:
package cloneobject;
import java.util.Arrays;
public class CloneObject {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
clone(new int[3][3]);
}
public static void clone(int[][] x) {
int[][] y = (int[][]) x.clone();
System.out.println("x=");
PrintFieldImage(x);
System.out.println("y=");
PrintFieldImage(y);
x[1][1] = 3;
System.out.println("x=");
PrintFieldImage(x);
System.out.println("y=");
PrintFieldImage(y);
y[2][2] = 4;
System.out.println("x=");
PrintFieldImage(x);
System.out.println("y=");
PrintFieldImage(y);
}
public static void PrintFieldImage(int[][] field) {
if (field != null) {
int x;
for (x = 0; x < field.length; x++) {
System.out.println(Arrays.toString(field[x]));
}
} else {
System.out.println("no field!");
}
}
}
そしてこれは結果です:
run:
x=
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
y=
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
x=
[0, 0, 0]
[0, 3, 0]
[0, 0, 0]
y=
[0, 0, 0]
[0, 3, 0]
[0, 0, 0]
x=
[0, 0, 0]
[0, 3, 0]
[0, 0, 4]
y=
[0, 0, 0]
[0, 3, 0]
[0, 0, 4]
BUILD SUCCESSFUL (total time: 0 seconds)
ここで、xに3を含め、yに4を含めたいと思います。
Plzヘルプ!