-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice33.java
More file actions
39 lines (35 loc) · 884 Bytes
/
Copy pathPractice33.java
File metadata and controls
39 lines (35 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fiftypratice;
/**
* 题目:打印出杨辉三角形(要求打印出10行如下图)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
…………
*
* */
public class Practice33 {
public static void main(String[] args) {
int [][]a=new int[10][10];
for(int i=0;i<10;i++){
a[i][i]=1;
a[i][0]=1;
}
for(int i=2;i<10;i++){
for(int j=1;j<i;j++){
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}
for(int i=0;i<10;i++){
for(int k=0;k<2*(10-i)-1;k++){
System.out.print(" ");
}
for(int j=0;j<=i;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}