Java的数组与循环操作实训

数组与循环操作:

编写chapters02类,要求该类中包含如下方法:
1、sum方法,有参数整型num,num≥10,计算1+2+3+……+num的值并返回结果。
2、factorial方法,有参数整型num1和num2,判断num1和num2值的大小,使用do…while计算其阶乘,返回结果。如factorial(5,10)和Factorial(10,5)其结果都应为5到10的阶乘。

5到10的阶乘 意思是5×6×7×8×9×10吗

ublic class chapters02 {
    public static int sum(int num) {
        if (num<10) {
            //num >10
            return 0;
        }else if(num == 10) {
            // 1+2+...+10
            return 55;
        } else {
            return num + sum(num-1);
        }
    }
    
    public static int factorial(int num1,int num2) {

        int start = 0;
        int end = 0;
        int result = 0;
        if(num1 > num2) {
            start = num2;
            end = num1;
        }else if(num2>num1){
            start =num1;
            end = num2;
        }else {
            return num1;
        }
        result = start;
        do {
            start +=1;
            result *= start;
        } while((end-start)>0);
        
        return result;
    }
    
}

你的老师是姓高吗?