Odpowiedź:
package com.company;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
static boolean isPrime(int number) {
int counter = 0;
for (int i = 2; i <= number; i++) {
if (number % i == 0) {
counter++;
}
}
return counter == 1;
}
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("plikLiczbyPierwsze2.txt"));
for (int i = 1000; i <= 10000; i++) {
if (isPrime(i)) {
bufferedWriter.write(i + "\n");
}
}
bufferedWriter.close();
}
}
Wyjaśnienie: