Nick Klemer
Nick Klemer

Reputation: 5

Compare Multiple Integers and find largest in java

I am kind of new to java, and I am making a MAbovePixel Generator. Right now my idea is that the very top pixels, and the very right pixels are blue, from then on the generator has a chance of making yellow(sand), then from there, ground, and grass.

So far, I have the 'generator' check the pixel above it, and the left of it. Depending on what color the pixel is, the current pixel has a chance of being one of the pixels next to it.

          if (LeftPixel == 0xFF0000FF) OceanChance = OceanChance + 5;
          if (AbovePixel == 0xFF0000FF) OceanChance = OceanChance + 5;
          if (LeftPixel == 0xFFEDC9AF) SandChance = SandChance + 5;
          if (AbovePixel == 0xFFEDC9AF) SandChance = SandChance + 5;
          if (LeftPixel == 0xFF733D1A) GroundChance = GroundChance + 5;
          if (AbovePixel == 0xFF733D1A) GroundChance = GroundChance + 5;
          if (LeftPixel == 0xFF698B22) GrassChance = GrassChance + 5;
          if (AbovePixel == 0xFF698B22) GrassChance = GrassChance + 5;

At this point, I am unsure what to do next. I have the list, but how do I check whats largest in Java?

How do I compare all the ints in the list, and depending on whats largest, do whatever. Or if theres a tie, randomly select a int to use anyway from a list of ties.

I did search on the internet "Java compare multiple integers", but it didn't come up with anything I could understand, so maybe theres a name for what im trying to do that I don't know about?

In any case, what is the best thing to do?

Upvotes: 0

Views: 1264

Answers (2)

soulcheck
soulcheck

Reputation: 36767

You iterate the list and find the maximum. If it's only 4 values you can write 4 if's comparing each one with the current maximum, although java jitter probably does just that.

edit:

or just use Collections#max()

Upvotes: 0

John B
John B

Reputation: 32949

So you have 4 Chance integers and you need to find the largest? If so put them in a sorted list TreeSet and get the last element in the list

Upvotes: 1

Related Questions