File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find the maximum value in an array

 
Uthpala Hathnagoda
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just a new to JAVA.
can you help me to find the maximum/minimum value in an array.
Thnx
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to loop through an array ?
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Uthpala Hathnagoda Welcome to JR.
You can achieve this in many ways- by using for loop (you may be done this in other languages like c,c++). Or there is one method in an Array name as sort(int[] arr). Using this method you can Sorts the array of into ascending numerical order. Once you get sorted array it is easy to find out max and min element in that array.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the idea is to find the maximum value without sorting. this is a common homework task for beginners. Please, Uthpala Hathnagoda, show us what you have got so far.

If you have got nowhere, get a pencil and paper and a large eraser. The eraser is by far the most useful piece of hardware . Write out an unsorted array of numbers. Write a maximum variable, give it an initial value, and write down how you think you can iterate through the array and get maximum to be equal to the largest value. Leave spaces after each line . . .



. . . then go back and enhance your algorithm by adding a minimum value.

The following sentences show what you are aiming for: all words of one syllable.
Once you have made that work well and work right, write down what you have done in small words. Then you can change what you wrote into code.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic