首页 > 解决方案 > 如何为此编写一个名为 product 的实例方法?(评论有说明)

问题描述

// An instance method named product, which
// multiplies the values between min and max and
// returns the result.  For example, if min = 6
// and max = 9, then this should return 3024
// (6 * 7 * 8 * 9).  If min is greater than
// max, then this should return 1.  

public int product() {
      int runningTotal = 1;

      for(int i = min; i < max + 1; i++) {
        runningTotal += i;
      }

      return runningTotal;
    }

标签: javamethodsinstance

解决方案


推荐阅读