java - Finding the maximum among three integers and knowing which one is chosen -


i working on code has find best solution. first check whether 1 of 3 larger other two. hence, there maximum occurs once. if there 2 numbers larger third one, equal each other, have compare distance of 2 , 1 smallest distance chosen.

the profit functions , distances calculated outside method , not important.

what have come far use lot of if statements. however, wondering whether there more efficient method this.

public void bestsolution(list<route> ls, list<route> sa, list<route> rr) {     int profitls = profitroutes(ls);     int profitsa = profitroutes(sa);     int profitrr = profitroutes(rr);      int distancels = totaldistance(ls);     int distancesa = totaldistance(sa);     int distancerr = totaldistance(rr);      if ((profitls > profitsa) & (profitls > profitrr))     {      }  } 

in case of finding max between 3 integers -

int mostprofit = math.max(profitls, math.max(profitsa, profitrr)); 

considering case - "distance of 2 , 1 smallest distance chosen"

class distanceprofit{    private int profit;    private int distance;     public distanceprofit(int profit, int distance){        this.profit = profit;        this.distance = distance;    } } ... //create distanceprofit objects add list  collections.sort(distenceprofitlist, new comparator<distenceprofit>{     public int compare(distenceprofit dp1, distenceprofit dp2){          if(dp1.getprofit()==dp2.getprofit())              return dp1.getdistance() - dp2..getdistance();          return dp1.getprofit() - dp2.getprofit();     } }); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -