Prime numbers are also called primes. A natural number greater than 1, if not divisible by other natural numbers except for 1 and itself, otherwise known as composite numbers. According to the basic theorem of arithmetic, each integer that is larger than 1 is either itself a prime number or a product of a series of prime numbers, and if the order of these primes in the product is not taken into account, the written form is unique. Here is a simple example of the prime number within Java for 100
Copy Code code as follows:
public class Test {
public static void Main (string[] args) {
int i,n,k=0;
for (n = 3; n<=100; n++) {//3~100 all numbers
i=2;
while (I<n) {
if (n%i==0) break; If you can divide it by stating that N is not prime, jump out of the current loop
i++;
}
if (i==n) {//if i==n indicates that n cannot be divisible by 2~n-1, is a prime
k++; Number of statistical outputs
System.out.print (i+ "T");
if (k%6==0)//Per output 5 lines will be wrapped
System.out.println ();
}
}
}
}