必须在JavaFX技术框架下做,不可采用AWT或Swing技术。
编写 GUI 程序。当用户在界面上输入任一个正整数 n 后,界面可显示 Fibonacci (斐波那契)数列第 n 项的值。
斐波那契数列,求解答
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
小飞LOVE霞 2022-05-31 15:30关注package com.wf.fx.demo01; import javafx.application.Application; import javafx.event.EventType; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.stage.Stage; import org.kordamp.bootstrapfx.scene.layout.Panel; import java.util.Arrays; public class HelloApplication extends Application { @Override public void start(Stage stage) { Panel panel = new Panel(); Label label = new Label(); TextField textField = new TextField(); Button button = new Button("计算"); button.addEventHandler(EventType.ROOT,event -> { label.setText(Arrays.toString(getF(Integer.parseInt(textField.getText())))); }); panel.setBody(textField); panel.setFooter(button); panel.setHeading(label); Scene scene = new Scene(panel, 320, 240); stage.setTitle("Hello!"); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(); } public static int[] getF(int value) { int n = value; int[] a = new int[n]; a[0] = 1; if (n > 1) { a[1] = 1; for (int i = 2; i < a.length; i++) { a[i] = a[i - 1] + a[i - 2]; } } return a; } }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用