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
• Ron McLeod
• Tim Cooke
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Paul Clapham
• Rob Spoor
• Junilu Lacar
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Piet Souris
• Carey Brown
Bartenders:

# Comparing the sums of rows and columns in a 2D array

Greenhorn
Posts: 15
• Number of slices to send:
Optional 'thank-you' note:
Here's the code I have for summing the totals of my columns and my rows.

I'm trying to figure out how to say if row one does not equal row two. I'm just not getting the syntax here.

If anyone could help I'd appreciate it.

Thanks

author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Lonnie Wood wrote:
I'm trying to figure out how to say if row one does not equal row two. I'm just not getting the syntax here.

Well, you are not saving the row totals (or the column totals) anywhere. You calculate a row total, print it, and then calculate the next row using the same variables.

You can't compare one row total to another because your program never have two row totals (at the same time) to allow for any comparison -- much less, for a specific comparison.

Henry

Lonnie Wood
Greenhorn
Posts: 15
• Number of slices to send:
Optional 'thank-you' note:
Henry,

I'm calculating the totals, but how do I store the value is a better question I guess. How can I say that columnTotal for column0 = columnTotal0 and columnTotal for column1 = columnTotal1?

Hence the reference to a syntax problem.

Thanks

Henry Wong
author
Posts: 23931
142
• Number of slices to send:
Optional 'thank-you' note:

Lonnie Wood wrote:

I'm calculating the totals, but how do I store the value is a better question I guess. How can I say that columnTotal for column0 = columnTotal0 and columnTotal for column1 = columnTotal1?

Have you tried creating an array for the column totals? Then you can say "columnTotals[col]" as the total for a particular column.

Henry

Lonnie Wood
Greenhorn
Posts: 15
• Number of slices to send:
Optional 'thank-you' note:
Henry,

No I haven't but that makes sense. Let me try that out and let you know.

Thanks

Marshal
Posts: 77158
370
• Number of slices to send:
Optional 'thank-you' note:
I take it you have a "rectangular" array, ie all the rows are the same length. Otherwise, if a row is longer than the first row, you will omit its last element and get a wrong answer. If a row is shorter, you will get the far less serious result of an Exception.

 Consider Paul's rocket mass heater.