Finding Minimum/Maximum of A Simple List
in
Programming Questions
•
2 years ago
Alright, so I've only been doing this programming stuff for a little while and I can't figure out how to find the maximum number from a .txt list.
This is what I have:
---
float amountMax;
float amountMin;
//float values;
void setup() {
size(1000, 500);
String[] lines = loadStrings("amounts.txt");
int numAmounts = lines.length;
float[] valuesArray = new float[numAmounts];
for (int i = 0; i < lines.length; i++) {
valuesArray[i] = float(lines[0]);
amountMax = max(valuesArray);
amountMin = min(valuesArray);
println(amountMax);
}
}
---
This returns a value of 100,000. This is not the highest number in the list.
The list is one that includes both blank lines and lines with numbers. It looks like this:
---
30000
40000
15000
22500
493573
230000
90000
30000
30000
480000
10000
65000
420000
10000
20000
---
Any ideas?
1