solution.json 1.4 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "12524157eec6409ab1b5e93fc9141608",
  "keywords": "算法高阶,数论算法,素数的测试,算法问题选编",
  "title": "求素数",
  "desc": [
    {
      "content": "\n求1-100内的素数",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "public static void main(String[] args){\n\t\tfor(int i=0;i<100;i++) {\n\t\t\tcheckPrime(i);\n\t\t}\n\t}\n\tprivate static void checkPrime(int x){\n\t\tboolean isPrime = true;\n\t\tif(x ==1 || x %2 ==0 && x !=2 )\n\t\t{\n\t\t\tisPrime = false;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor( int i =3; i< Math.sqrt(x); i+=2)\n\t\t\t{\n\t\t\t\tif( x % i == 0)\n\t\t\t\t{\n\t\t\t\t\tisPrime = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif( isPrime)\n\t\t{\n\t\t\tSystem.out.println(x +\"是素数\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(x+ \"不是素数\");\n\t\t}\n\t}",
    "language": "java"
  },
  "node_id": "dailycode-f0884125382f41c592c2346b73f34e30",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470193"
}