Okay my new question is how I can let the array print out all numbers of the segment. At the moment I can input a number and the code will print out the corresponding value in Fibonacci. However, I would like the array to print out all values leading up to the answer. Ex. Input = 7, array prints out 0, 1, 1, 2, 3, 5, 8 instead of just 8
package math;
public class Fibonacci {
public static long getFib(int n) {
long Fibby[] = new long[n+1];
Fibby[0] = 1;
Fibby[1] = 1;
for(int i = 2; i<=n; i++) { //initialize loop
Fibby[i] = Fibby[i-1] + Fibby[i-2];
} // end of for loop
return Fibby[n]; //end method getfib
}
}
And the runner
package math;
Scanner key = new Scanner(System.in);
Fibonacci f = new Fibonacci();
int p;
System.out.println("Fib value : ");
p = key.nextInt();
System.out.println( "Fib Value of "+ p +" :: " + f.getFib(p) );
}
How can this happen? My question has been downsized.
package mathsupposed to do? All the code you're showing is base java. Also, what areradiusandheight? (your code doesn't use them, Fibbonacci numbers certainly don't use them, why are they in the method signature and call?)