First show the results:
Introduction:
Yang Hui's triangle is a geometric arrangement of binomial coefficients in a triangle. In Europe, this table is called the Pascal Triangle. Pascal (1623----1662) discovered this rule in 1654, 393 years later than Yang Hui and 600 years later than Jia Xian. The Yang Hui triangle is one of the outstanding research results of ancient Chinese mathematics. It graphs the binomial coefficients and intuitively reflects some of the inherent algebraic properties of combined numbers from the figures. It is a beautiful combination of discrete numbers and shapes.
The example code is as follows:
package com.sxt;import java.util.Arrays;public class KeBen {public static void main(String[] args) {int[][] array =new int [10][10];array [0]=new int[]{1};//The first line is 1for (int i=1;i<10;i++){array[i]=new int [i+1];for (int j=0;j<i+1;j++){if(j==0||j==i){//Border special processing array[i][j]=1;} else{//Equal to the sum of the two shoulders of the previous line array[i][j]=array[i-1][j]+array[i-1][j-1];}}}//Simple output for (int i=0;i<10;i++){System.out.println(Arrays.toString(array[i]));}//Type out for (int i=0;i<10;i++){for (int j=0;j<10-i-1;j++){System.out.print(" ");//Two spaces} for (int j=0;j<=i;j++){String a=""+array[i][j];//Convert to a string//The length of the string should be considered separately if(a.length()==1){a=" "+a+" ";}if(a.length()==2){a=" "+a;}System.out.print(a+" ");}System.out.println();}}}Summarize
The above is the entire content of this article about the implementation of the two output results of Yang Hui triangle in Java programming. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!