i have problem about the output in this code, my output so only the index 0.
how can i fix this.

public class d_2D {
     static double[][] d =new double[6][4];
           
   static  double[][] e=    {{},
                        {0.0,0.6,0.0,0.0},
                        {0.0,0.2,0.5,0.1},
                        {0.0,0.2,0.5,0.4},
                        {0.0,0.2,0.5,0.7},
                        {0.0,0.0,0.0,0.9}};
       
     
     
    static   double[] avg= new double[4];  
       static double[] sum= new double[4];
     static  int i,j,k;
     
     
    public double getAverage(int j){
        return  avg[j]= sum[j]/k  ; 
            }
    public void setAverage(int i, int j,int k){
         //average of column 
        
          for(j=1;j<e[1].length;j++){   
        
           sum[j]=0.0;
           k=0;
             for( i= 1; i < e.length; i++)
                                         
            if(e[i][j]>0.0){
                sum[j] += e[i][j];
                k++;
        }
          }
    }
    public double getElement(int i, int j) { 
      
         return  d[i][j]=Math.abs(e[i][j]-avg[j]); 
    }
    public void setElement(int i, int j,int k) { 
        
        for(j=1;j<e[1].length;j++){     
            for( i= 1; i < e.length; i++)
                                         
            if(e[i][j]>0.0){
                sum[j] += e[i][j];
                k++;
    }
         }  }
    public static void main(String args[])
        {
     //   d_2D d_2D = new d_2D();
        
        System.out.println("Average of j[" + j + "] = " +avg[j]);
        System.out.println("d[" + i + "][" + j + "] = " + d[i][j]);
 
   }
}

PLease use CODE tags to enclose your code.

And please tell us what you want to do... what the program is for... etc.
and whats the output and what do you want as output. Please state clearly.

And your current code will only print

Average of j[0] = 0
d[0][0] = 0

Because you haven't modified any data elements and they contain their initial values only which is 0.

can you post which part of your code do you need help or wish to add something?

and like what stevanity said, please post what the program is for, its hard for us to pinpoint exactly what part of the code needs a change or something

thanks for ur all replied, i want to claculate d[j],from index 1 to index 5, and i got the output only Average of j[0] = 0 and d[0][0] = 0 and i want the output d[j] from this file to use in another class.java flie but in the same package
example this class is d_2D.java and i want to use d[j] in here to claculate in bb.java that average h and f[j] by d[j]

Example:
h[1]=avg (d[1][1]+d[1][2]+.....+d[1][5])
f[1]=avg (d[1][1]+d[2][1]+d[3][1])

Dear sir,

can u advice me more: i want to claculate d[j],from index 1 to index 5, and i got the output only Average of j[0] = 0 and d[0][0] = 0 and i want the output d[j] from this file to use in another class.java flie but in the same package
example this class is d_2D.java and i want to use d[j] in here to claculate in bb.java that average h and f[j] by d[j]

Example:
h[1]=avg (d[1][1]+d[1][2]+.....+d[1][5])
f[1]=avg (d[1][1]+d[2][1]+d[3][1])

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.