java核心技术读后感

来源:互联网 发布:刺客信条枭雄低配优化 编辑:程序博客网 时间:2024/05/16 16:12

原文229页的获取数组的最大最小值的方法,写反了

public class ArrayUtil {

 public static class Pair{
  private int frist;
  private int scend;
  
  public Pair(int frist, int scend)
  {
   super();
   this.frist = frist;
   this.scend = scend;
  }

  public int getFrist() {
   return frist;
  }

  public void setFrist(int frist) {
   this.frist = frist;
  }

  public int getScend() {
   return scend;
  }

  public void setScend(int scend) {
   this.scend = scend;
  }
  
  public static Pair getMinMax(int[] array)
  {
   int min = Integer.MIN_VALUE;
   int max = Integer.MAX_VALUE;
   for (int i : array)
   {
    if(min >i)min = i;//此处是原文的将不会得到最小值而是Integer.MIN_VALUE
    if(max < i)max = i;//不会得到最大值

//以上两处应该把大小于符号调换
   }
   return new Pair(min, max);
  }
  
 }
}

 

原创粉丝点击