File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

J. Moritz
Greenhorn

Joined: Nov 18, 2004
Posts: 9
I've been working on this problem all evening and any help would be appreciated.

I have a 5 element array (of type integer). I need to find the element of the array that holds the maximum value and keep the original corresponding index of that element. The Arrays.sort won't work on this one becuase the index changes for the element with the maximum value once the elements are sorted in ascending order.

Can anyone give me any example code? I just can't figure it out.. I've tried nested loops and etc..

Thanks
Mark Patrick
Ranch Hand

Joined: Feb 22, 2004
Posts: 51
Without sorting the array, you'll have to loop through the array one time and test for the int value to be greater the previous greatest value:



Mark Patrick<br />SCJP 1.4
J. Moritz
Greenhorn

Joined: Nov 18, 2004
Posts: 9
finding the minimum and maximum values of an array while still retaining their original corresponding indices:

J. Moritz
Greenhorn

Joined: Nov 18, 2004
Posts: 9
Thanks Mark!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays
 
Similar Threads
DataStructure for getting the maximum element in int array
Wrapper Class
Problem with the date 2005-07-14
compare two arraylists and get position of common elements
Problem Finding Index Value of a String in Array