Solved

How to find the highest number using an array

Posted on 2003-12-01
5
432 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

747 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

11 Experts available now in Live!

Get 1:1 Help Now