First of all, we must understand what prime numbers (prime numbers) are, and the definition of prime numbers:
For a number greater than 1, if it cannot be any more than 1 and itself, If it is divisible by other positive integers, then we say it is a prime number.
Method to determine whether a number is a prime number (prime number):
If it is an even number, return directly; then start from 3, with a step size of 2, until n If the arithmetic square root cannot be divided, it is a prime number.
The examples are as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Recommended tutorial: java introductory tutorial
The above is the detailed content of How to determine whether a number is prime (prime number) in java. For more information, please follow other related articles on the PHP Chinese website!