我从模拟试卷中被困在这个问题上。我需要将“from”数字乘以“n”数字。换句话说:from*(from+1) (from+2) ...*n。
我需要通过使用while循环来解决这个问题。到目前为止我已经这样做了,不知道该怎么做。
class Fact {
private int factPartND(final int from, final int n) {
int c = 1;
int z = from;
int y = n;
int num = 0;
while (y >= z) {
num += from * (from + c);// need to stop multiplying from for each
// iteration?
c++;
y--;
}
return num;
}
public static void main(String[] args) {
Fact f = new Fact();
int test = f.factPartND(5, 11);
System.out.println(test);
}
}