# How to get array.length after calculating greater(less) than?

**URL:** https://discourse.processing.org/t/how-to-get-array-length-after-calculating-greater-less-than/4336
**Category:** Coding Questions
**Created:** [October 10, 2018, 4:53pm UTC](https://discourse.processing.org/t/how-to-get-array-length-after-calculating-greater-less-than/4336 "2018-10-10T16:53:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![SolDrakibane](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/soldrakibane/32/1810_2.png) [@SolDrakibane](https://discourse.processing.org/u/SolDrakibane)
#### Post date: [October 10, 2018, 4:53pm UTC](https://discourse.processing.org/t/how-to-get-array-length-after-calculating-greater-less-than/4336/1 "2018-10-10T16:53:37Z")

</div>

Alright, so i have numbers that i need to calculate in this code. And i need to calculate all the array numbers above 5.5 and set them into a .length so i can calculate the amount of sufficient scores. I also need to do this in the opposite. My attempt at the second tab is shown below with a method called _geefAantalVoldoendes_.

I can’t wrap my head around this.

Also i would appreciate feedback on the code so i can improve and understand what you would do or what would be the better practice.

_ALSO! Thank god for **Open Draft** on this forum. I made a bunch of code and the power just shorted - lost almost everything but the forum function actually saved my code, lol._

**Main tab**

```auto
String bestand = "cijfers_klein.txt";
//String bestandGroot = "cijfers_groot.txt";

void setup() {
  size(600, 400);
  float[] cijfers = laadCijfers(bestand);
  int arrayLength = geefAantal(cijfers);
  float arrayHoogste = geefHoogste(cijfers);
  float arrayLaagste = geefLaagste(cijfers);
  float arrayGemiddelde = geefGemiddelde(cijfers);
  int voldoendes = geefAantalVoldoendes(cijfers);
}

```

**Second tab**

```auto
/*
 geefAantal, 
 geefHoogste, 
 geefLaagste, 
 geefGemiddelde, 
 geefAantalVoldoendes,
 geefAantalOnvoldoendes
 loadStrings()
 */

float[] laadCijfers(String bestand) {
  float[] cijfers = float(loadStrings(bestand));
  return cijfers;
}

static final int geefAantal(float[] laadArray) { 
  int cijfer = laadArray.length;
  println("Print aantal cijfers: "+cijfer);
  return int(cijfer);
}

float geefHoogste(float[] laadArray) { 
  float cijfer = laadArray[0]; 
  for (int i = 1; i < laadArray.length; i++) { 
    if (laadArray[i] > cijfer) { 
      cijfer = laadArray[i];
    }
  }
  println("Print hoogste cijfer: "+cijfer);
  return cijfer;
}

float geefLaagste(float[] laadArray) { 
  float cijfer = laadArray[0]; 
  for (int i = 1; i < laadArray.length; i++) { 
    if (laadArray[i] < cijfer) { 
      cijfer = laadArray[i];
    }
  }
  println("Print laagste cijfer: "+cijfer);
  return cijfer;
}

float geefGemiddelde(float[] laadArray) {
  float cijfer = laadArray[0];
  for (int i = 1; i < laadArray.length; i++) { 
    cijfer += laadArray[i];
  }
  cijfer /= laadArray.length;
  println("Print gemiddelde cijfer: "+nf(cijfer, 1, 1));
  return cijfer;
}

/*Voldoende is alles boven 5.5; dus GETAL >= 5.5 == voldoende.
 - print lengte - alleen alles boven 5.5
 */
static final int geefAantalVoldoendes(float[] laadArray) {
  float cijfer = laadArray[0];
  float voldoende = 5.5;
  for (final int i = 1; i < laadArray.length; i++) {
    cijfer = laadArray[i];
    if (cijfer >= voldoende) {
    }
  }

return int(cijfer);
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 10, 2018, 9:51pm UTC](https://discourse.processing.org/t/how-to-get-array-length-after-calculating-greater-less-than/4336/2 "2018-10-10T21:51:46Z")

</div>

```java
@SafeVarargs static final int geefAantalVoldoendes(
  final float voldoende, final float... laadArray) {
  int counter = 0;
  if (laadArray != null && laadArray.length > 0)
    for (final float f : laadArray) if (f >= voldoende) ++counter;
  return counter;
}

```

---

<div class="post-metadata">

### Author: ![SolDrakibane](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/soldrakibane/32/1810_2.png) [@SolDrakibane](https://discourse.processing.org/u/SolDrakibane)
#### Post date: [October 11, 2018, 11:25am UTC](https://discourse.processing.org/t/how-to-get-array-length-after-calculating-greater-less-than/4336/3 "2018-10-11T11:25:51Z")

</div>

Just by reading the code i actually understand it. Man i’ve been thinking too hard about it haha.  
Thanks @GoToLoop i really appreciate it, you guys are awesome. I’ve found this code on the forum before (or the old forum) by googling, but i couldn’t understand the code. Now that you’ve adjusted it to my code i actually understand it. I also didn’t know about the ?: operator that you can use it as an else.
