Reputation: 843
what I am trying to do, is get the minimun and maximun value from some float values I put manually. But I do not know how to do it. any helping coidng would be great. Thank you. Asume a list of floats p1, p2, p3, p4, p5, p6, p7, p8, p9
Upvotes: 1
Views: 2210
Reputation: 1474
Add float values in ArrayList
val simpleArray = arrayOf(55.4, 20.0, 99.99, 1.99, 23.0, 34.2, 88.0, 72.1, 61.2, 43.9)
then use these two simple functions like below
val largestElement = simpleArray.max()
val smallestElement = simpleArray.min()
Upvotes: 2
Reputation: 134
You can use a List Collection like ArrayList and use the default sorting method provided by the library - Collections.sort(list) and fetch the first and last element
List<Float> list = new ArrayList<Float>();
list.add(13.3);
list.add(134.3);
list.add(1.3);
Collections.sort(list);
float min = list.get(0); //1.3
float max = list.get(list.size-1); //134.3
Upvotes: 2