findprimes.java
来自「JAVA 2 入门经典 的 书上代码」· Java 代码 · 共 23 行
JAVA
23 行
public class FindPrimes
{
public static void main(String[] args)
{
int nPrimes = 100; // The maximum number of primes required
OuterLoop:
for(int i = 2; ; i++) // This loop runs forever
{
// Try dividing by all integers from 2 to i-1
for(int j = 2; j < i; j++)
{
if(i % j == 0) // This is true if j divides exactly
continue OuterLoop; // so exit the loop
}
// We only get here if we have a prime
System.out.println(i); // so output the value
if(--nPrimes == 0) // Decrement the prime count
break; // It is zero so we have them all
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?