|
- import java.util.*;
6 y3 f Z7 G' K* C5 O) G
: N# ^8 L, k' g% `- p9 q- public class Main{
* @1 x! n3 C: y -
, h3 m/ F. ^; ]& w# y - public static void main(String[] args) { ! m+ S/ w4 B8 J
- Scanner in=new Scanner(System.in);" E8 I+ w( V8 s. a
- System.out.println("请输入行数");0 [ M! ?" ^* |& R2 a0 |
- int a=in.nextInt();* @! `1 T% }; Z) E
- int num[][] = new int[a][a];- J/ |2 y& P$ N% w
- for(int m=0;m<a;m++){; S1 s7 b/ |7 N, ]5 v0 p. L6 {$ @! }
- for(int n=0;n<=m;n++){$ O. x8 _/ f% V/ `" T, `- S8 q' L
- if(n==0||m==n){* N. c7 c+ ^6 h+ d6 ^0 q) Y. L
- num[m][n]=1;
2 S. O* D- L% I P+ A: i8 K2 O, { - }& Z, u/ P( `9 w) b7 }
- else" O& k( m" F1 }9 Y) g7 _2 t. s1 R
- num[m][n]=num[m-1][n-1]+num[m-1][n];
3 A: y" O: s. ^0 a7 W - }
+ ]. V1 K4 N9 T: f; x: W- L - }
~& \4 i4 \9 e% J& c/ s - for(int i=0;i<a;i++){, C. }+ L' x0 F- J) }2 Q
- for(int l=i;l<a;l++){
f, K# o6 ~7 i8 I. p! z* I - System.out.print(" ");
0 {% x& @4 o. K2 s8 A. ? - }
& B1 W9 t& i0 a0 ~+ M( l l1 G - for(int j=a-i;j<=a;j++){ V2 |8 }" ~ v9 x; B
- System.out.print(num[i][a-j]+" ");/ z. b: U4 A% x: ?$ T9 z9 _' I7 e
- }
+ ?2 A. C$ @) c - System.out.println();
: P: B) m# U* `# T - }
3 j/ b9 O; j! [/ f* B9 |0 l - }
, R6 l% n3 f$ Z( E: g; H+ U - }5 p) Z& u; r9 @2 N6 A( G
复制代码 |
|