FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   possible? max(myArray[]);
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: possible? max(myArray[]);  (Read 310 times)
sspboyd


possible? max(myArray[]);
« on: Feb 6th, 2004, 11:21pm »

Am I just wishing or is it possible to use the max() function to determine the largest value in an array of floats or integers?  
Is there some other similar method (since I tried the code below and it obviously doesn't work)?
 
Code:
println(max(myArray[]));

cue music  
"when you wish upon a var, it makes a difference what the methods are...."  
(sorry, I couldn't help myself! )
 

gmail.com w/ sspboyd username
benelek

35160983516098 WWW Email
Re: possible? max(myArray[]);
« Reply #1 on: Feb 7th, 2004, 2:12pm »

lol, where do you go to way a pie? somewhere over the rainbow... way... a... pie.
 
you can't use the max() method as you describe, but here's a piece of code that will find what you want:
 
Code:

int[] a = { 2,5,1,3 };
int maximum=0;
for(int i=0; i<a.length; i++) {
  if(a[i]>maximum) maximum=a[i];
}
//the value of maximum is that max value.

 
and this will sort an array of floats or integers into ascending numerical order:
 
Code:

int[] a = {2,6,1,3};
Arrays.sort(a);
//now a={1,2,3,6} so you can find the maximum value by reading a[a.length-1]
 
Pages: 1 

« Previous topic | Next topic »