aspose file tools*
The moose likes Beginning Java and the fly likes Two dimensional array total and sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Two dimensional array total and sort" Watch "Two dimensional array total and sort" New topic
Author

Two dimensional array total and sort

Ryan Mcguin
Greenhorn

Joined: Dec 17, 2008
Posts: 4
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

Joined: Dec 17, 2008
Posts: 4
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

Joined: Oct 13, 2005
Posts: 36508
    
  16
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Two dimensional array total and sort
 
Similar Threads
double array file cleared up
Arrays with files
Sorting arrays while retaining original index
Something i'm extremely confused on
summing each row in a 2-dimensional array