# Minimum non zero value of array

**URL:** <https://discourse.processing.org/t/minimum-non-zero-value-of-array/6889>\
**Category:** Coding Questions\
**Created:** [December 25, 2018, 3:33pm UTC](https://discourse.processing.org/t/minimum-non-zero-value-of-array/6889 "2018-12-25T15:33:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fonsinho](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@fonsinho](https://discourse.processing.org/u/fonsinho)\
**Post date:** [December 25, 2018, 3:33pm UTC](https://discourse.processing.org/t/minimum-non-zero-value-of-array/6889/1 "2018-12-25T15:33:18Z")

</div>

Hi, i create this sketch for working…but i can´t take minimum non zero value

Some suggestions?

tks

```auto
//ArrayList<int []> yo=new ArrayList<int []>();
//Pilo pilo;
int[] a ={3,56,0,12,
          8,7,6,5,
          5,6,0,33};
int H = 0;
int M = 0;
int N=1;
int d =3;
int j =4;
int h=0;
int [] p=new int[4];  
int [] q=new int[9]; 
 int x=0;
int y=0;
int f=0;

void draw(){
  //for(x=0; x<12;x++)
  for ( y=0;y<3;y+=1){

    arrayCopy(a,h,p,0,4);
    H=max(p);
    M=min(p);

    h+=j;
   
    if(y==2)
      h=0;

    println(p);
    println(M);
  }
}

```

---

<div class="post-metadata">

**Author:** ![janglee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/janglee/32/4035_2.png) [@janglee](https://discourse.processing.org/u/janglee)\
**Post date:** [December 25, 2018, 5:17pm UTC](https://discourse.processing.org/t/minimum-non-zero-value-of-array/6889/2 "2018-12-25T17:17:44Z")

</div>

here you go

```auto
//ArrayList<int []> yo=new ArrayList<int []>();
//Pilo pilo;
int[] a ={3,56,0,12,
          8,7,6,5,
          5,6,0,33};
int H = 0;
int M = 0;
int N=1;
int d =3;
int j =4;
int h=0;
int [] p=new int[4];  
int [] q=new int[9]; 
 int x=0;
int y=0;
int f=0;

void draw(){
//for(x=0; x<12;x++)

for ( y=0;y<3;y+=1){

   arrayCopy(a,h,p,0,4);
   
      
 

  H=max(p);
  M=findSmallest(p);

   h+=j;
   
 if(y==2)
    h=0;

   println(p);
   println(M);
}
}

public static int findSmallest(int[] arr) {
    int smallest = Integer.MAX_VALUE;
    for(int i=0; i<arr.length; i++) {
        if(arr[i] > 0 && arr[i]<smallest) {
            smallest = arr[i];
        }
    }
    return smallest;
}

```

---

<div class="post-metadata">

**Author:** ![fonsinho](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@fonsinho](https://discourse.processing.org/u/fonsinho)\
**Post date:** [December 25, 2018, 5:22pm UTC](https://discourse.processing.org/t/minimum-non-zero-value-of-array/6889/3 "2018-12-25T17:22:08Z")

</div>

mmmm…very good!!!

finally i make this

```auto
//ArrayList<int []> yo=new ArrayList<int []>();
//Pilo pilo;
int[] a ={3,56,0,12,
          8,7,6,4,
          9,6,0,33};
int H = 0;
int M = 0;
int N=1;
int d =3;
int j =4;
int h=0;
int [] p=new int[4];  
int [] q=new int[9]; 
 int x=0;
int y=0;
int f=0;
// polo=new ArrayList<Pilo>();
void draw(){
 int i=0;
for ( y=0;y<3;y+=1){
 // f=a[y];
    arrayCopy(a,h,p,0,4);  
  
 
for ( i=0;i<4;i+=1){ 
  if(p[i]==0){p[i]=max(p);}
  H=max(p);     
  M=min(p);
   println(p[i]);
}     
   h+=j;   
if(y==2)  
h=0; 

//line (M,y+30,H,y+30);
 println (M);
 }
}

```

---

<div class="post-metadata">

**Author:** ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)\
**Post date:** [December 25, 2018, 6:07pm UTC](https://discourse.processing.org/t/minimum-non-zero-value-of-array/6889/4 "2018-12-25T18:07:53Z")

</div>

Congratulations on your success!

As an off-topic suggestion, I suggest you to name your variables more descriptively, instead of `H` `M` `N` `d` `j` `h` etc…  
This way, you may forget what they do in the future, and no one else would be able to understand your code until digging into it and figuring out what it’s supposed to do!
