Prime numbers are also called prime numbers. A natural number greater than 1, if it cannot be divided by other natural numbers except 1 and itself; otherwise it is called a composite number. According to the basic theorem of arithmetic, each integer larger than 1 is either a prime number itself or can be written as the product of a series of prime numbers; and if the order of these prime numbers in the product is not taken into account, the written form is unique. Below is a simple example of java to find prime numbers within 100
The code copy is as follows:
public class test {
public static void main(String[] args) {
int i,n,k=0;
for (n = 3; n<=100; n++) { // All numbers from 3~100
i=2;
while (i<n) {
if (n%i==0) break; //If divisible, it means that n is not a prime number, break out of the current loop
i++;
}
if (i==n) { //If i==n, it means that n cannot be divisible by 2~n-1, it is a prime number
k++; //Statistics the number of outputs
System.out.print(i+ "/t ");
if (k %6==0) //For every 5 outputs, line break
System.out.println();
}
}
}
}