• 杨辉三角(java实现)


     1 package lizi;
     2 import java.util.Scanner;
     3 public class Yanghui {
     4     private static Scanner input;
     5     public static void main(String[] args) {
     6         test_YH();
     7     }
     8     public static void test_YH() {
     9         System.out.print("请输入行数:");
    10         input = new Scanner(System.in);
    11         int row = input.nextInt();
    12         int col = row;
    13         int[][] array = new int[row][col];
    14 
    15         for (int i = 1; i < row; i++) {
    16             for (int j = row; j > i; j--) {
    17                 System.out.print("  ");
    18             }
    19             for (int j = 1; j <= i; j++) {
    20                 if (i == j || j == 0) {
    21                     array[i][j] = 1;
    22                 } else {
    23                     array[i][j] = array[i - 1][j - 1] + array[i - 1][j];
    24                 }
    25                 System.out.print(array[i][j] + "   ");
    26             }
    27             System.out.println();
    28         }
    29     }
    30 }
    昔日我曾苍老,如今风华正茂(ง •̀_•́)ง
  • 相关阅读:
    Safari-IoS调试
    前端加密技术
    gulp入门
    xss攻击
    xml 解析
    python 基本语法
    python初识
    字节
    神奇的算式
    linux-虚拟机安装
  • 原文地址:https://www.cnblogs.com/lgqrlchinese/p/8998246.html
Copyright © 2020-2023  润新知