我正在尝试创建此方法,但是由于某种原因它无法正常工作...

public static Interval multiply(Interval x, Interval y) {
   int min = Math.min(x.lo * y.lo, x.hi * y.hi, x.hi * y.lo, x.hi * y.hi);
   int max = Math.max(x.lo * y.lo, x.hi * y.hi, x.hi * y.lo, x.hi * y.hi);
   return new Interval(min, max);


它与Math.min / Math.max有关,但是我查了一下,所以不确定是否正确使用它?

最佳答案

丑陋,但是:

public static Interval multiply(Interval x, Interval y) {
   int min = Math.min(Math.min(Math.min(x.lo * y.lo, x.hi * y.hi), x.hi * y.lo), x.hi * y.hi);
   int max = Math.max(Math.max(Math.max(x.lo * y.lo, x.hi * y.hi), x.hi * y.lo), x.hi * y.hi);
   return new Interval(min, max);

07-28 04:17
查看更多