Solved

How to find the highest number using an array

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i compare an object based on two fields 6 54
fibonacci ten numbers 4 38
java jdbc batch example 8 34
Java exception bubble up 2 18
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

773 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