How would you write a Java program to check if a number is prime?
The program should start by checking if the number is less than 2, as numbers less than 2 arenâ€™t prime. Then loop through numbers from 2 to the number minus 1.
You're correct that numbers less than 2 arenâ€™t prime. But you can optimize the loop by stopping at sqrt(n) instead of going up to `n-1`.
Can you modify your approach to stop the loop at the square root of the number?