didikee - 博客园

for循环实现斐波拉切数列的前N项,N由用户输入。

public static void main(String[] args) {
        System.out.println("请输入位数:");
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int first = 1, second = 1, next;
        System.out.print("1" + "1");
        for (int i = 3; i <= N; i++) {
            next = first + second;
            first = second;
            second = next;
            System.out.print(next);
        }
    }

 

posted @ 2018-12-18 12:21  排雷兵  阅读(483)  评论(0编辑  收藏  举报
//粒子吸附特效
  
*
*
*
*
*
*
*
*
*
*
*
*
*