我被要求在执行isPrime方法中的if语句之前跟踪此程序(仅在for循环的第一次迭代中)。那么如何追踪这个程序?记忆中有什么?什么是输出?
package hwprime;
public class HWPrime {
public static boolean isPrime (int number) {
for (int div =2; div <= number / 2; div++)
if (number % div == 0)
return false; // we found a number div that num is divisible by
return true;
}
public static void main(String[] args) {
System.out.println(" is a number a prime number?");
int x = 41;
if (isPrime (x) )
System.out.println(x + " is a prime number");
}
}