Analyze the following requirements , And realize it with code :
(1) Printing 1-100 All primes and numbers between (2) Output per line 5 A number that satisfies the condition , Space between notes : Prime is division 1 And what he thought , It can't be divided by other natural numbers
This is a simple programming logic problem , At first glance, it seems very simple , But computer programming is not so simple , Because we understand the logic :

This number cannot be divided by other numbers , Of course, it must be less than it ( Divisor divided by divisor equals quotient ).

The computer wants to know if it can be divided by a number less than it , You can only count one by one , So we set up a loop :
int i , j , count = 0; for (i = 2 ; i <= 100 ; i++){
// Give Way i Divide by every number less than it , If you can divide it , It shows that it is not a prime number , Just skip the loop for (j = 2 ; j < i ; j++) { if (i % j ==
0) { break; } } // If the above cycle continues , Finally realized j++, Unqualified , Jump out of the loop , that i = j if (i == j) {
// In order to make five prime numbers output on one line if (count % 5 == 0) { System.out.println(); } count++;
//println Wrap lines for output System.out.print(i + " "); } } }

Technology