Tue Oct 21, 2008 4:38 pm
public
{
public static void main(String[ ] args)
{
int[][] table = { {1,2,3}, {1,2,3}};
int row, column;
for (row = 0; row <table.length; row++)
{
for(column = 0; column<table[ row].length; column++)
System.out.print( table[row][column]) ;
System.out.println( );
}
int[] val = sum1(table);
for(int k=0; k<val.length; k++)
System.out.print(val[k]+" ");
}
public static int[] sum1 (int[][] numbers)
{
int sum[] = new int[numbers[0].length]; /* Change1: set sum[] 's
length to (numbers[0].length) */
for (int i = 0; i < numbers[0].length;
i++) /*Change 2: change the cond'n */
{ /
*(k<numbers.length) to (k<numbers[0].length) */
int total = 0;
for (int j = 0; j < numbers.length;
j++) /*Change 3: change the cond'n
(k<numbers[0].length) to (k<numbers.length) */
total += numbers[j][i]
; //Change 4 : replacce
[i] each other [j]
//System.out.print( total);
sum[i]=total;
//System.out.println( );
}
return sum;
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.