zoukankan      html  css  js  c++  java
  • 【JAVA】杨辉三角

    ソース

     1 public Yanghui3jiao() {
     2     List<String[]> rowList = new ArrayList<String[]>();
     3     List<String[]> newList = new ArrayList<String[]>();
     4     for (int i = 22; i > 0; i--) {
     5         String str[] = new String[i];
     6         for (int j = 0; j < str.length; j++) {
     7             if (j == 0 || j == str.length - 1) {
     8                 str[j] = "1";
     9             } else {
    10                 str[j] = "0";
    11             }
    12         }
    13         rowList.add(str);
    14     }
    15 
    16     String tmp[] = null;
    17 
    18     for (int i = rowList.size() - 1; i > 0; i--) {
    19         String str[] = rowList.get(i);
    20         if (tmp != null) {
    21             for (int x = 1; x < str.length - 1; x++) {
    22                 str[x] = String.valueOf((Integer.valueOf(tmp[x - 1]) + Integer.valueOf(tmp[x])));
    23             }
    24         }
    25         newList.add(str);
    26 
    27         for (int o = 1; o < (rowList.size() - str.length); o++) {
    28             System.out.print(" ");
    29         }
    30 
    31         for (int j = 0; j < str.length; j++) {
    32             System.out.print(str[j] + " ");
    33         }
    34         System.out.println("");
    35         if (str.length != 1) {
    36             tmp = str;
    37         }
    38     }
    39 }
  • 相关阅读:
    springboot整合mybatis
    nginx
    mysql安装
    oracle安装静默
    网卡
    kafak部署
    在docker环境下安装activemq和rabbitmq
    docker安装
    【1213工作日志】ZYNQ的中断应用
    【CAN总线】CAN总线总结
  • 原文地址:https://www.cnblogs.com/lnsylt/p/10176799.html
Copyright © 2011-2022 走看看