需要一个java编写得程序,要输出任何一个数得范围内得所有质数,而且,每一步还要带有详细注释,有高分,加分得。速度,坐等答案。
package com.javacodegeeks.snippets.basics;
public class GeneratePrimeNumbersWithForLoop {
public static void main(String[] args) {
int max = 100;
System.out.println("Generate Prime numbers between 1 and " + max);
// loop through the numbers one by one
for (int i = 1; i<max; i++) {
boolean isPrimeNumber = true;
// check to see if the number is prime
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrimeNumber = false;
break; // exit the inner for loop
}
}
// print the number if prime
if (isPrimeNumber) {
System.out.print(i + " ");
}
}
}
}