これは過去の試験問題からの質問です。コードは質問で与えられました、そして私は値とブレークポイントが何回あるかを取得する必要があります。eclipseでコードを実行しようとしましたが、役に立ちませんでした。(コードが実行された場合、デバッグモードで値を見つけることができました)
fact
また、質問には次のように記載されています。値が6のクラスのインスタンスでメソッドが呼び出されn
ます。コードが質問で指定されたものとまったく同じであるため、何が間違っているのかわかりません。
public class FactLoop {
private int n;// assumed to be greater than or equal to 0
/**
* Calculate factorial of n
*
* @return n!
*/
public int fact() {
int i = 0;
int f = 1;
/**
* loop invariant 0<=i<=n and f=i!
*/
while (i < n) {// loop test (breakpoint on this line)
i = i++;
f = f * i;
}
return f;
}
// this main method is not a part of the given question
public static void main(String[] args) {
FactLoop fl = new FactLoop();
fl.n = 6;
System.out.println(fl.fact());
}
}