【程式語言】JAVA的第六堂課 |1*2+2*3+3*4+4*5+5*6+…+ n*(n-1)遞迴練習題
Published:
by .public class hw7_23 {
public static int rsum(int n) {
if ( n == 1 || n == 2) {
return 2;
}
else {
return n * (n-1) + rsum(n-1);
}
}
public static void main(String[] args) {
System.out.println(rsum(5));
}
}