Minimum non zero value of array

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

Some suggestions?

tks

//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);
  }
}
1 Like

here you go

//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;
}
1 Like

mmmm…very good!!!

finally i make this

//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);
 }
}
1 Like

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!

4 Likes