How to find a max value with loop

How do I find the maximum and minimum value of an array with loops?

1 Like

Look at this

2 Likes

For some reason I don’t know Processing is not giving the minimum and maximum values when I used the standard logical code to get minimum and maximum values so I resorted to use Processing Syntax. Good luck with your project.

int houses = {25,30,18,105,33,10,17,8,65};
void setup(){
size(400,400);
background(200);

int maxXM = max(houses);
int minXM = min(houses);
//println(maxXM);
//print(minXM);

}

void draw(){
}

Processing’s container IntList has both min() & max() methods:

How about taking a peek on how they’re implemented straight from their source?

1 Like

Hello @Chigoz,

Please follow instructions here for posting code:
https://discourse.processing.org/faq#format-your-code

This is what you are posting:
image

This is what you should be posting:

int [] houses = {25, 30, 18, 105, 33, 10, 17, 8, 65};

Properly formatted and posted code helps the community focus on the code instead of the errors from a quick cut and paste.

:)

1 Like

Ok, I’ll learn that, is formatting possible using a phone?

I do not use my phone for this.

I suggest you start a separate topic on the subject and users with experience can advise you.

This would be of great benefit to others as well!
There are a lot of sloppy posts recently and this may be related to their development environment.

Details are important.

What are you using to develop your code on the phone?

:)

1 Like

Recently for some reason I don’t know some websites do not load on my Google Chrome browser hence after I write the code in Processing IDE I transfer it over the internet to my phone and if there is any need to do further work on the code. I edit the code with my phone and run it on OpenProcessing.

No need for a long winded approach, depending on the array type, if its just ints or floats its simple

int[] list = {1,6,7,3,5,6,3,4,2,8};

println(max(list));
2 Likes

The need is determined by the the original poster.

The original poster may be a beginner and understanding basic loops and search algorithms is an important first step and a very common question.

It is important to master the basics and also nice to have the options of the helper methods for consideration.

I may have been a bit long winded…

:)

2 Likes

No, not long winded, you make a good point, its better to know HOW the functions work at their core then just using them

2 Likes

The thing is that the loop goes on and one, and I have the maximum and minimum value a lot of times.

Hello @mvb,

Think about what the loop is doing and where you want these statements:

  print(min);
  print(max);

Consider using println() instead.

I am seeing “this piece of code” in other posts as well with different user names.

Is this a homework assignment?

:)

1 Like