/
* * Use a two-dimensional array to print a 10-row Yang Hui triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 ten 5 1
....
"Hint"
1. The first line has 1 elements, and the nth row has n elements
2. The first and last elements of each row are 1
3. Starting with the third row, for elements that are not the first and last element.
YANGHUI[I][J] = Yanghui[i-1][j-1] + yanghui[i-1][j];
*
/public class Test_03yanghui {public
static void Main (string[] args) {
//1. Create a two-dimensional array of the specified format
int[][] Yanghui = new int[10][];
for (int i = 0; i < yanghui.length; i++) {
Yanghui[i] = new int[i+1];
}
2. Assign a value for the two-dimensional array for
(int i = 0; i < yanghui.length; i++) {
yanghui[i][0] = yanghui[i][i] = 1;
if (i > 1) {for
(int j = 1; j < Yanghui[i].length-1; J + +) {
yanghui[i][j] = yanghui[i-1][j-1] + Yan GHUI[I-1][J];}}
}
3. Traverse the two-dimensional array for
(int i = 0; i < yanghui.length; i++) {for
(int j = 0; J < Yanghui[i].length; J + +) {
S Ystem.out.print (Yanghui[i][j] + "");
}
System.out.println ();}}}