Here is the code:
class Fibonacci {
static final int MIN_INDEX = 1;
public static void main (String[] args){
int high = 1;
int low = 1;
String jel;
System.out.println("9: " + high);
for (int i = 8; i >= MIN_INDEX; i--){
if (high % 2 == 0)
jel = " *";
else
jel = " ";
System.out.println(i + ": " + high + jel);
high = low + high;
low = high - low;
}
}
}
I want to write this program, to store the Fibonacci sequence in an array, and then write out them. But I can’t write it. What can I do? I don’t need to “mark them” with an *.
I think this will answer your question (I also added handling for some pessimistic scenarios):
The
buildFibArraymethod builds the array.The
printFibArraymethod prints the array – should be according to your requirements.