到目前为止我有这个,结果是一个空白屏幕。我可以做些什么来达到列出前 46 个斐波那契数字的预期效果?
TextView fibNum;
static int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static int fib(int n) {
int prev1=0, prev2=1;
for( i=0; i<n; i++) {
int savePrev1 = prev1;
prev1 = prev2;
prev2 = savePrev1 + prev2;
}
return prev1;
}
public void main(String[] args) {
for (int i=0; i<=46; i++)
fibNum = new TextView(this);
fibNum.setText(String.valueOf(fib(i)+", "));
}
}