2D arrays
createArray(): This method must create a 2D array of doubles that has 2 rows and 3 columns. Fill in each array element with the value of 2 * it's row number plus 2 * it's column number. Then, write a nested for loop that goes through the array and adds up all the numbers, and prints the sum to the screen.
This is the code
publicclass ArrayStuff2D{
publicstaticvoid main(String args[])
{
ArrayStuff2D a =new ArrayStuff2D();
double array1[][] ={{1,2,3},{4,5,6}};
double [][]sum = a.createArray(array1);
}
publicdouble [][]createArray(double[][] ar)
{
double ans = 0.0;
double ans1[0] =newdouble[ar.length];// rows
double ans1[1] =newdouble[ar[0].length];
for (int r=0; r < ar.length; r++)
{
for (int c=0; c < ar[r].length; c++)
{
// Add each row total;
ans1[0][r] += 2 * ar[r][c];
// Sum of each column
ans1[1][c] += 2 * ar[r][c];
ans = ans1[0][r] + ans1[1][c];
}
}
return ans;
// ans[0] contains sum of each row
// ans[1] contains sum of each col
}
}
This is not working?is my logic wrong

