Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

# totaling array rows and columns

Greenhorn
Posts: 23
• Number of slices to send:
Optional 'thank-you' note:
I can total my whole array. but now I am trying to do a total for the rows and an total for the columns. I am stuck on how I need to manipulate the code to just print by row and column seperate.

Thanks Ryan.

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
------------------------------------------------------------
I can total my whole array. but now I am trying to do a total for the rows and an total for the columns. I am stuck on how I need to manipulate the code to just print by row and column seperate.
--------------------------------------------------------------
int rowTotal = 0;
int colTotal =0 ;
for(int row = 0; row < sales.length; row++){
for(int col = 0; col < sales[row].length; col++){
rowTotal += sales[row][col];
}
System.out.println("Row Total for the row:"+(row+1)+
" = "+rowTotal);
rowTotal = 0;
}
for(int col = 0; col < sales[0].length; col++){
for(int row = 0; row < sales.length; row++){
colTotal += sales[row][col];
}
System.out.println("Col Total for the col:"+(col+1)+
" = "+colTotal);
colTotal = 0;
}

 Thank you my well lotioned goddess! Here, have my favorite tiny ad! Free, earth friendly heat - from the CodeRanch trailboss https://www.kickstarter.com/projects/paulwheaton/free-heat