程序应该根据小于25的用户输入打印出数组中的索引...所以如果用户输入7,应该显示数组的七个第一个元素....不知道我为什么会得到边界错误。我也无法绕过For Loop的工作方式。
import java.util.Scanner; 公共类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");
}
}
}