I need help with my java-program. This program is supposed to ask for the highest value fibonacci can have, and print out the number of series up to that value, but it doesn't work. Any suggestions?
import java.util.Scanner;
public class Fibonacci {
public static void main (String[] args){
Scanner in = new Scanner(System.in);
System.out.println("The largest number fibonacci can be: ");
int number = in.nextInt();
if (number < 0){
System.out.println("Wrong! Max-value has to be at least 0.");
}
int i;
int f0 = 0;
int f1 = 1;
int fn;
int value=0;
for (i = 0; i<=value; i++){
fn = f0 + f1;
System.out.println("Fibonacci-number " + i + " = " + f0);
f0 = f1;
f1 = fn;
value = number - f0;
}
}
}
If i put in number = 12
, the program is supposed to print:
fibonacci-number 0 = 0
...
fibonnaci-number 12 = 144