Finding two major peaks and the valleys between the peaks of a 2D array or histogram

后端 未结 1 1920
忘了有多久
忘了有多久 2021-01-16 09:23
for (int i = 0; i < c.length; i++)
{
    for(int j=0; j

        
1条回答
  •  -上瘾入骨i
    2021-01-16 09:38

    maybe something like this?

    import java.util.*;
    color[][]  c = new color [10][2];
    
    
    void setup() {
      for (int i = 0; i < c.length; i++) {
        for (int j = 0; j < c[0].length; j++) {
          c[i][j] = color(random(255), random(255), random(255));
        }
      }
    
      float[] reds = new float[c.length*c[0].length];
    
      for (int i = 0; i < reds.length; i++) {
        if ( i < c.length)
          reds[i] = red(c[i][0]);
        else
          reds[i]=red(c[i-c.length][1]);
      }
      println("\n unsorted red values");
      println(reds);
      Arrays.sort(reds);
      println("\nSORTED");
      println(reds);
    
      println("\n\n the bigger red value is: " + reds[reds.length-1]); 
      println("\n the 2nd bigger red value is: " + reds[reds.length-2]); 
      println("\n the smaller red value is: " + reds[0]); 
      println("\n\n cheers");
    }
    

    0 讨论(0)
提交回复
热议问题