⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primes.java

📁 非常好的java事例以及带源码事例的java2教程
💻 JAVA
字号:
public class Primes 
{
   public static void main(String[] args)
   {
      int nValues = 50;                        // The maximum value to be checked
      boolean isPrime = true;                  // Is true if we find a prime

      // Check all values from 2 to nValues
      for(int i = 2; i <= nValues; i++)
      {
         isPrime=true;                         // Assume the current i is prime

         // 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
            {
               isPrime = false;    // If we got here, it was an exact division
               break;              // so exit the loop
            }
         }

      // We can get here through the break, or through completing the loop
      if(isPrime)                  // So is it prime?
         System.out.println(i);    // Yes, so output the value
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -