Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

max/min value function  RSS feed

 
Mark Phylus
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that reads the temperature values for each day for the entire year. I want to get the highest and the lowerst values of my read data. How? I will appreciate any suggestion
 
srinivas daroori
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not aware of any striaght forward way for doing this. But I think you can do like this.
While reading the values itself you can store another value called maxValue in a variable. For example the first time temperature reading is temp. Store this in the maxValue too .. maxValue = temp.
Now onwards whenever your read temp, store the maxValue in the variable maxValue. Like maxValue = Math.max(temp, maxValue); Hope this helps.
 
Mike Fuellbrandt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the above is not feasible, you could sort them using the Arrays.sort() (or Collections.sort() as the case may be) methods and get the elements temps[0] and temps[temps.length -1]
You may have to implement Comparable or Comparator depending...
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by highest and lowest data? I'm assuming you have more than one data per day? You need some kind of sorting algorithm, unless speed is your primary concern, almost anyone of them would work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!