• 杨辉三角形


    package com.shan;

    import java.util.Scanner;

    public class YFTriangle {

        public static void main(String[] args) {
            printYFTriangle();
        }

        /** * 1 要理解下面的实现,首先要明白int数组中元素默认值为 0 * 2 然后每一次迭代打印新的一行的元素的时候: * 新的特定位置的元素 = 该位置原来的元素 + 该位置的前一个位置的值 */
        public static void printYFTriangle(){
            System.out.println("how many lines you want:");
            Scanner in = new Scanner(System.in);
            int lines = in.nextInt();
            int[] a = new int[lines + 1];
            int previous = 1;
            for (int i = 1; i <= lines; i ++){
                for (int j = 1; j <= i; j++){
                    int current = a[j];
                    a[j] = previous + current;
                    previous = current;
                    System.out.print(a[j] + " ");
                }
                System.out.println();
            }
        }

    }

  • 相关阅读:
    shell提交hive sql保存运行过程日志
    hive中 exists与left semi join
    hbase shell 导出数据转json
    ubuntu使用
    fast json
    elasticsearch 用户密码配置
    linux 自带php切换xampp
    Ubuntu查看crontab运行日志
    Linux服务器 XAMPP后添加PHP和MYSQL环境变量
    HBuilder 模拟器
  • 原文地址:https://www.cnblogs.com/cw8514----/p/6633838.html
Copyright © 2020-2023  润新知