java - Determine the row and column with the largest sum -


i have finished of code. problem last part have determine row , column largest sum. managed , print largest sum of row , column, however, wanted print number of row , column largest sum is. instead of printing value of largest sum, want print row , column of largest sum.

i hope of understand.

here code

    public static void main(string[] args) {         // todo auto-generated method stub          int[][] arr = new int[10][10];         int [] sumrow = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};         int [] sumcol = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};         int sumall = 0;         int largestrow=0;         int largestcol=0;          for(int i=0; i<arr.length; i++) {             for(int r=0;r<arr.length; r++){                 for(int c=0; c<arr.length; c++){                       arr[i][i] = (int)(math.random()*10 + 1);                  }                 system.out.print(arr[i][i]+"  ");                  sumrow[i]= sumrow[i]+ arr[i][i];                 sumall = sumall+ arr[i][i];                 sumcol[r]=sumcol[r]+ arr[i][i];                 if(sumrow[i]>largestrow){                     largestrow=sumrow[i];                 }                 if(sumcol[r]>largestcol){                     largestcol=sumcol[r];                 }              }          system.out.println();         }         system.out.println("sum element :" +" "+ sumall);         system.out.println("sum row :");         for(int i=0; i<arr.length; i++) {             system.out.println((i+1) + ": " + sumrow[i]);     }         system.out.println("sum column :");          for(int i=0; i<arr.length; i++) {             system.out.println((i+1) + ": " + sumcol[i]);     }         system.out.println("the row largest sum :" + " " + largestrow);         system.out.println("the column largest sum :" + " " + largestcol);       }     } 

declare 2 more integers:

int largestrowindex=0; int largestcolindex=0; 

store , r when find max rowsum colsum:

if(sumrow[i]>largestrow){     largestrow=sumrow[i];     largestrowindex = i; } if(sumcol[r]>largestcol){     largestcol=sumcol[r];     largestcolindex = r; } 

use in printed information:

system.out.println("the row largest sum :" + " " + largestrow + " @ index " + largestrowindex); system.out.println("the column largest sum :" + " " + largestcol+ " @ index " + largestcolindex); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -