AleGasp
29-09-2013, 22:53
Chiedo aiuto :D
Sto facendo un corso di Java, sono alle prime armi, e non riesco a risolvere questo piccolo problema.
Devo trovare tutti i numeri primi della serie di Fibonacci fino a 1000.
Elimino tutti i numeri pari, ma poi non riesco ad eliminare i numeri dispari che mi danno resto zero :mc:
@SuppressWarnings("empty-statement")
public static void main(String[] args) {
int first, second , next, check, i;
first = 1; // Start from 1 and not 0 because the first prime number is 2
second = 1;
check = 2;
System.out.println("I numeri primi di fibonacci fino a mille sono \n");
for (i=3; i<1000; i=i+2) {
}
for(next=2; next<900; next++){ /* Limit at 900 because for logic the sum of the two previous numbers
* is over 1000. If I set the limit at 1000 the last result will be more than 1000. */
next = first+second;
first = second;
second = next;
if (next<=check){
next=check;
System.out.println("" +next);
}
if ((next%check)!=0){
if ((next%i)!=0){
System.out.println("" +next);
}
} else {
}
}
// TODO code application logic here
}
}
Sto facendo un corso di Java, sono alle prime armi, e non riesco a risolvere questo piccolo problema.
Devo trovare tutti i numeri primi della serie di Fibonacci fino a 1000.
Elimino tutti i numeri pari, ma poi non riesco ad eliminare i numeri dispari che mi danno resto zero :mc:
@SuppressWarnings("empty-statement")
public static void main(String[] args) {
int first, second , next, check, i;
first = 1; // Start from 1 and not 0 because the first prime number is 2
second = 1;
check = 2;
System.out.println("I numeri primi di fibonacci fino a mille sono \n");
for (i=3; i<1000; i=i+2) {
}
for(next=2; next<900; next++){ /* Limit at 900 because for logic the sum of the two previous numbers
* is over 1000. If I set the limit at 1000 the last result will be more than 1000. */
next = first+second;
first = second;
second = next;
if (next<=check){
next=check;
System.out.println("" +next);
}
if ((next%check)!=0){
if ((next%i)!=0){
System.out.println("" +next);
}
} else {
}
}
// TODO code application logic here
}
}