wer kann

Status
Nicht offen für weitere Antworten.
G

gast

Gast
das hier mal kommentieren für mich?

Code:
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.BitSet;
 
public final class Primzahl {
 
    private static void doIt(int SIZE) throws IOException {
        long t1, t2;
        final char newLine = '\n';
        final PrintWriter writer = new PrintWriter(
                new FileWriter("results.txt"));
        BitSet set = new BitSet(SIZE);
        t1 = System.currentTimeMillis();
        set.set(0);
        set.set(1);
        writer.println(2);
        for (int i = 4; i < SIZE; i += 2) {
            set.set(i);
        }
        int end = (int) Math.sqrt(SIZE);
        for (int i = 3; i < end; i += 2) {
            if (!set.get(i)) {
                for (int j = i * i; j < SIZE; j += i) {
                    set.set(j);
                }
                writer.println(i);
            }
        }
        if (end % 2 == 0)
            end++;
        for (int i = end; i < SIZE; i += 2)
            if (!set.get(i))
            {
                writer.println(i);
            }
 
        writer.flush();
        writer.close();
        t2 = System.currentTimeMillis();
 
        System.out.println((double) (t2 - t1) / 1000.0);
    }
 
    public final static void main(String[] args) throws IOException {
 
        doIt(10000);
    }
}
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Oben