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;

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;
static double[] sum= new double;
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.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.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]);

}
}``````

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
d = 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 and d = 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=avg (d+d+.....+d)
f=avg (d+d+d)

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 and d = 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=avg (d+d+.....+d)
f=avg (d+d+d)

Be a part of the DaniWeb community

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