Guten Tag liebes Forum!
Ich studiere Wirtschaftsinformatik und habe als Refreshment mal ein paar Project Euler Aufgaben lösen wollen! Nun bin ich bei Aufgabe 10 ein bisschen verwirrt!
Folgende Aufgabenstellung:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Mein Code:
Ich komme mit diesem Code auf 1179908154. Jedoch ist das falsch!
Vielen Dank für eure Hilfe.
Burri44
Ich studiere Wirtschaftsinformatik und habe als Refreshment mal ein paar Project Euler Aufgaben lösen wollen! Nun bin ich bei Aufgabe 10 ein bisschen verwirrt!
Folgende Aufgabenstellung:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
Mein Code:
Java:
public static void main(String[] args) {
int sum = 2;
System.out.print("2");
for(int i = 3;i<2000000;i++){
boolean c = false;
for(int b = 2;b<i/2+1;b++){
if(i%b==0){
c = true;
break;
}
}
if(c==false){
System.out.print(" + " + i);
sum = sum+i;
}
}
System.out.println(" = " +sum);
}
Ich komme mit diesem Code auf 1179908154. Jedoch ist das falsch!
Vielen Dank für eure Hilfe.
Burri44
Zuletzt bearbeitet: