Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的数组元素在Java中具有相同的id?_Java_Jquery_Arrays - Fatal编程技术网

我的数组元素在Java中具有相同的id?

我的数组元素在Java中具有相同的id?,java,jquery,arrays,Java,Jquery,Arrays,这是一个将两个稀疏矩阵相乘的程序。我有一个SpEntry类型的数组(一个包含3个即时变量的类,int row、column、value、getter和setter方法),当我想设置为我的对象创建的数组的元素时(m_1和m_2是类SpArray的实例,每个类都有一个SpEntry[]SpArray,大小与它们的非零元素相同) 当我想设置每个数组的元素时,我喜欢m_1[0]、&m_1[1](m_1数组的元素)具有相同的id,因此当我设置m_1[0]的行、列、val时,元素也会为m_1[1]的行、列、

这是一个将两个稀疏矩阵相乘的程序。我有一个SpEntry类型的数组(一个包含3个即时变量的类,int row、column、value、getter和setter方法),当我想设置为我的对象创建的数组的元素时(m_1和m_2是类SpArray的实例,每个类都有一个SpEntry[]SpArray,大小与它们的非零元素相同) 当我想设置每个数组的元素时,我喜欢m_1[0]、&m_1[1](m_1数组的元素)具有相同的id,因此当我设置m_1[0]的行、列、val时,元素也会为m_1[1]的行、列、val重复

public class SpArray {
    public static int N ; //size of NxN matrix
    private SpEntry[] spArray;

    public SpArray(int nNZ){
        spArray = new SpEntry[nNZ];  //nNZ is the number of Non-Zero elements of the sparse matrix

        SpEntry init = new SpEntry(0,0,0);
        for (int s=0; s<spArray.length ; s++){
            spArray[s]= init ; 

        }

    }




    //returns the spArray
    public SpEntry[] getSpArray (){
        return this.spArray;
    }




    //returns the spArray elements
        public SpEntry getSpArray (int index){
            return this.spArray[index];
        }
System.out.println(“请在第一个稀疏矩阵中输入非零元素的数量:”); nnz_1=input.nextInt()

你的问题是:

public SpArray(int nNZ){
    spArray = new SpEntry[nNZ];  //nNZ is the number of Non-Zero elements of the sparse matrix

    SpEntry init = new SpEntry(0,0,0);       // Problem here
    for (int s=0; s<spArray.length ; s++){
        spArray[s]= init ; 

    }

}
publicssparray(int-nNZ){
spArray=new SpEntry[nNZ];//nNZ是稀疏矩阵的非零元素数
SpEntry init=新的SpEntry(0,0,0);//这里的问题
对于(int s=0;s
    m_1 = new SpArray (nnz_1);

    for(int j_1=0; j_1<nnz_1 ; j_1++){
    System.out.println("Enter number "+ (j_1+1) + " non-zero element of the 1st sparse matrix");
        System.out.println("row: ");
        int r_1 = input.nextInt();
        System.out.println("column: ");
        int c_1 = input.nextInt();
        System.out.println("Value: ");
        int v_1 = input.nextInt();


        /*
        SpEntry e_1 = new SpEntry (r_1, c_1, v_1);
        m_1.getSpArray()[j_1].setRow(e_1.getRow());
        m_1.getSpArray()[j_1].setCol(e_1.getCol());
        m_1.getSpArray()[j_1].setVal(e_1.getVal());
        */

        //new versiin revised
        SpEntry e_1 = new SpEntry (r_1, c_1, v_1);
        m_1.getSpArray(j_1).setRow(e_1.getRow());
        m_1.getSpArray(j_1).setCol(e_1.getCol());
        m_1.getSpArray(j_1).setVal(e_1.getVal());**

    } 
m_1           Value: SpArray (id=21)`enter code here`
  spArray            SpEntry[2] (id=22)
    [0]              SpEntry   (id=661)
    [1]              SpEntry   (id=661)
public SpArray(int nNZ){
    spArray = new SpEntry[nNZ];  //nNZ is the number of Non-Zero elements of the sparse matrix

    SpEntry init = new SpEntry(0,0,0);       // Problem here
    for (int s=0; s<spArray.length ; s++){
        spArray[s]= init ; 

    }

}
public SpArray(int nNZ){
    spArray = new SpEntry[nNZ];  //nNZ is the number of Non-Zero elements of the sparse matrix

    for (int s=0; s<spArray.length ; s++){
        spArray[s]= new SpEntry(0,0,0) ; 

    }

}