Hallo Leute!
Bin neu hier im Forum und muss eine HA lösen. Wäre nett, wenn ihr mir das weiterhelfen könntet.
Die Aufgabe besteht darin mithilfe des Siebes von Eratosthenes (also aus dem erzeugten Array), eine N-Anzahl an Primzahlen auf dem Bildschirm auszugeben. Also ich gebe als Parameter eine Zahl N ein und diese gibt mir dann N-Primzahlen aus.
Das Sieb habe ich schon programmiert, aber wie ich das mit der Ausgabe hinbekommen soll, weiß ich leider nicht.
Hier der Code, den ich schon fertig habe:
Bin neu hier im Forum und muss eine HA lösen. Wäre nett, wenn ihr mir das weiterhelfen könntet.
Die Aufgabe besteht darin mithilfe des Siebes von Eratosthenes (also aus dem erzeugten Array), eine N-Anzahl an Primzahlen auf dem Bildschirm auszugeben. Also ich gebe als Parameter eine Zahl N ein und diese gibt mir dann N-Primzahlen aus.
Das Sieb habe ich schon programmiert, aber wie ich das mit der Ausgabe hinbekommen soll, weiß ich leider nicht.
Hier der Code, den ich schon fertig habe:
Code:
[LIST=1]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]java.util.*[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000000][B]class[/B][/COLOR] Sieb[COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000000][B]static[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] main [COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bstring%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]String[/COLOR][/URL] [COLOR=#009900][[/COLOR][COLOR=#009900]][/COLOR]args[COLOR=#009900])[/COLOR][COLOR=#009900]{[/COLOR]
[*] [COLOR=#000066][B]int[/B][/COLOR] max [COLOR=#339933]=[/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Binteger%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Integer[/COLOR][/URL].[COLOR=#006633]parseInt[/COLOR][COLOR=#009900]([/COLOR]args[COLOR=#009900][[/COLOR][COLOR=#cc66cc]0[/COLOR][COLOR=#009900]][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000066][B]boolean[/B][/COLOR] [COLOR=#009900][[/COLOR][COLOR=#009900]][/COLOR]istPrim [COLOR=#339933]=[/COLOR] [COLOR=#000000][B]new[/B][/COLOR] [COLOR=#000066][B]boolean[/B][/COLOR] [COLOR=#009900][[/COLOR]max[COLOR=#009900]][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]for[/B][/COLOR] [COLOR=#009900]([/COLOR][COLOR=#000066][B]int[/B][/COLOR] i[COLOR=#339933]=[/COLOR][COLOR=#cc66cc]2[/COLOR][COLOR=#339933];[/COLOR] i[COLOR=#339933]<[/COLOR]istPrim.[COLOR=#006633]length[/COLOR][COLOR=#339933];[/COLOR]i[COLOR=#339933]++[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] istPrim[COLOR=#009900][[/COLOR]i[COLOR=#009900]][/COLOR][COLOR=#339933]=[/COLOR][COLOR=#000066][B]true[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]for[/B][/COLOR] [COLOR=#009900]([/COLOR][COLOR=#000066][B]int[/B][/COLOR] i[COLOR=#339933]=[/COLOR][COLOR=#cc66cc]2[/COLOR][COLOR=#339933];[/COLOR] i[COLOR=#339933]<[/COLOR]istPrim.[COLOR=#006633]length[/COLOR][COLOR=#339933];[/COLOR]i[COLOR=#339933]++[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]for[/B][/COLOR] [COLOR=#009900]([/COLOR][COLOR=#000066][B]int[/B][/COLOR] j[COLOR=#339933]=[/COLOR][COLOR=#cc66cc]2[/COLOR][COLOR=#339933];[/COLOR]i[COLOR=#339933]*[/COLOR]j[COLOR=#339933]<[/COLOR]istPrim.[COLOR=#006633]length[/COLOR][COLOR=#339933];[/COLOR]j[COLOR=#339933]++[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] istPrim[COLOR=#009900][[/COLOR]i[COLOR=#339933]*[/COLOR]j[COLOR=#009900]][/COLOR][COLOR=#339933]=[/COLOR][COLOR=#000066][B]false[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]for[/B][/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]int[/B][/COLOR] i[COLOR=#339933]=[/COLOR][COLOR=#cc66cc]2[/COLOR][COLOR=#339933];[/COLOR]i[COLOR=#339933]<[/COLOR]istPrim.[COLOR=#006633]length[/COLOR][COLOR=#339933];[/COLOR]i[COLOR=#339933]++[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR][COLOR=#009900]([/COLOR]istPrim[COLOR=#009900][[/COLOR]i[COLOR=#009900]][/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#666666][I]//System.out.println(istPrim[I]); // true und false Ausgabe[/I][/COLOR]
[*] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bsystem%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]System[/COLOR][/URL].[COLOR=#006633]out[/COLOR].[COLOR=#006633]println[/COLOR][COLOR=#009900]([/COLOR]i[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR] [COLOR=#666666][I]// Ausgabe der Primzahlen [/I][/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*][COLOR=#009900]}[/COLOR]
[/LIST]