The program should print out the indexes in the array based on user input less than 25...so if the user enters in 7 the seven first elements of the array should be displayed....Not sure why I am getting a bounds error. I also having trouble wrapping my head around how the For Loop works.
import java.util.Scanner; public class FibbonacciSequencce {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int[] anarray = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34,55,89,144,233,377,610,987,1597,2584,
4181,6765,10946,17711,28657,46368 };
System.out.println("Please enter a number, less than 25,: ");
int number = input.nextInt();
if (number< 25){
for (int element=0; element<= number; element++){
number = number +element;
System.out.println(anarray[number]);
}
}
else {
System.out.println(" Enter a number less that 25");
}
}
}