実験課題2
Exercise 2(課題2) See the section 2.1.2. "printf Debugging". Explain the reason why the following method can not execute by following instructions.
- create the Java application project named
chapter2kadai2. - create
calcDivisorsmethod andmainmethod in the same Main class. - add some codes for the printf debugging to the class.
- take a screenshot of the execution result.
public static void calcDivisors(int n) {
for (int i = 0; i <= n; i = i + 1) {
if (n % i == 0) {
System.out.print(i + " ");
}
}
System.out.println();
}
calcDivisors to enumerate all divisors of n
calcDivisors method with n = 10(2.1.2.節をよく読み、chapter2kadai2プロジェクトを作成し、与えられたnの約数をすべて表示するcalcDivisorsメソッドと、calcDivisorsメソッドを実行するmainメソッドを作成しなさい。そしてprintfデバッグを行ってiやnがどの値のときに例外を発生するのか、エラーの原因を説明しなさい。)