Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two dimensional array total and sort

 
Ryan Mcguin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I, again, need to print the employees, their hours and have it sorted in descending order of total hours... i have this so far now...


[edit]Add code tags. CR[/edit]
[ December 17, 2008: Message edited by: Campbell Ritchie ]
 
Ryan Mcguin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I have gotten here so far but my printout is my big problem yet again... hmmm?

[edit]Add code tags and delete unnecessary newlines. CR[/edit]
[ December 17, 2008: Message edited by: Campbell Ritchie ]
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the code button and a consistent indentation convention; this is a good example. I have added code tags so you can see how much better they look.

Please tell us what problem you are having; I can see a potential problem which you might not have noticed.

When you are iterating through an array with a for loop the preferred style is

for (int i = 0; i < myArray.length; i++) . . .

Don't try varying it and don't put numbers in there (except the 0); that format always works.
[Pedantic mode]There is no such thing as a 2-D array in Java, only an array of arrays; since the arrays are often different lengths that form of for loop will still work when you change it to
for (int j = 0; j < myArray[i].length; j++) . . . [/pedantic mode]

And you could also try this format

for (int i = myArray.length - 1; i >= 0; i--) . . .

Now tell us what you think the problem is

And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic