This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes totaling array rows and columns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "totaling array rows and columns" Watch "totaling array rows and columns" New topic
Author

totaling array rows and columns

Ryan Perlman
Greenhorn

Joined: Oct 31, 2001
Posts: 23
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.
Suni Das
Greenhorn

Joined: Nov 27, 2001
Posts: 2
------------------------------------------------------------
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;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: totaling array rows and columns
 
Similar Threads
Write a method that can be called, that will initialize the seating plan.
jtable
Problem with indexing of an array
Arrays with files
Comparing the sums of rows and columns in a 2D array