• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two dimensional array total and sort

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic