Solved

How to find the highest number using an array

Posted on 2003-12-01
5
433 Views
Last Modified: 2010-03-31
Hello,

i have a problem which i have been trying to figure out for a couple of days but i can't seem to think of anyway of doing it, i am developing a little tool for myself to keep track of my scores in a sport i play...

The problem is here,

I have an array (size 11) with integers inside. I want to find the highest integer (i.e. score) in that array.

so for example if i have the following numbers in the array... 60, 12, 34, 56, 106 ... i would like to some how take the largest number out of the array which is 106 and store it in a int type variable.

This will allow me to keep track of my highest score. I have tried using a for loop but failed miserably, does anyone have an idea of how i can do this?

Thanks for your help.
0
Comment
Question by:Programmer_to_be
  • 4
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9851485
Are you sure it isn't homework? ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9851492
int max = Integer.MIN_VALUE;
for(int i = 0;i < int.length;i++) {
      if (ints[i] > max)
            max = ints[i];
}
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 9851598
Woops

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

should be

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

where 'ints' is your array of integers
0
 

Author Comment

by:Programmer_to_be
ID: 9851729
Hi CEHJ

Thanks for the help, i can assure you it's not homework! (However it would be great if i was taught Java rather than having to self learn it!)

Thanks again.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9851738
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now