Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 443
  • Last Modified:

How to find the highest number using an array

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
Programmer_to_be
Asked:
Programmer_to_be
  • 4
1 Solution
 
CEHJCommented:
Are you sure it isn't homework? ;-)
0
 
CEHJCommented:
int max = Integer.MIN_VALUE;
for(int i = 0;i < int.length;i++) {
      if (ints[i] > max)
            max = ints[i];
}
0
 
CEHJCommented:
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
 
Programmer_to_beAuthor Commented:
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
 
CEHJCommented:
:-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now