모의 검사 용지에서이 질문에 답해야합니다. 'from'숫자를 'n'숫자에 곱해야합니다. 즉, * from (from + 1) (from + 2) ... * n.Java - while 루프를 사용하여 계산 문제 해결
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);
}
}
출력이 이상적으로 5 * 6 * 7 * ... * 11이어야합니까? –
네 목표는 – nsc010