新入门菜鸟,老师讲课的时候睡着了,求大神可以逐条讲解一下<(* ̄▽ ̄*)/<(* ̄▽ ̄*)/
class DengCha {int start, d;
DengCha() { }
DengCha(int start, int d) {
this.start = start;
this.d = d;
}
void setStart(int s) {
start = s;
}
void setD(int d) {
this.d = d;
}
int getSum(int n) {
int sum = 0, i = 1;
while (i <= n) {
sum = sum + start;
start = start + d;
i++;
}
return sum;
}
}
public class ZuoYe2_1 {
public static void main(String args[]) {
DengCha shulie = new DengCha(2, 3);
System.out.println(shulie.getSum(100));
shulie.setStart(10);
shulie.setD(5);
System.out.println(shulie.getSum(9));
}
}