I came across a Java program which finds whether the given number is a prime. here is the code.
class FindPrime {
public static void main(String args[]) {
int num;
boolean isPrime;
num = 14;
if (num < 2)
isPrime = false;
else
isPrime = true;
for (int i = 2; i <= num / i; i++) {
if ((num % i) == 0) {
isPrime = false;
break;
}
}
if (isPrime)
System.out.println("Prime");
else
System.out.println("Not Prime");
}
}
Here, I'm not sure why the condition i <= num/i is used in the for loop. Can someone please explain me?