|
- import java.util.*;! f7 E( V( x7 E3 Q/ ^! E: Y
- , |1 @! {' e" r; R8 R4 S0 @$ v
- public class Main{/ g* j6 _ f- E
- ! j' p8 [% O' B9 P2 s) r! Z
- public static void main(String[] args) { 9 L/ O: G2 u% ^7 } s
- Scanner in=new Scanner(System.in);
; Z$ h }0 w( n- e) U - System.out.println("请输入行数");4 `; g- X: t9 W2 i% g
- int a=in.nextInt();6 G0 x- a$ C/ F& P
- int num[][] = new int[a][a];4 L0 v/ w! {) j) z
- for(int m=0;m<a;m++){0 a0 f* w7 q7 P7 [8 e: J+ H7 c1 J
- for(int n=0;n<=m;n++){, b/ q. ^7 U* g
- if(n==0||m==n){
" @+ A7 S2 A. P+ v5 s3 B" T; R - num[m][n]=1;, k3 q0 A/ |9 X& P' V
- }5 t$ C) k6 I i9 [# M7 u
- else
( d4 \8 `) [* s' e r1 |4 `# j - num[m][n]=num[m-1][n-1]+num[m-1][n];6 H( w# [0 x. C& y/ l
- }
5 \ Q) i/ G; V3 u" ^ - }4 K" {2 _# a$ P. U7 D3 B) N
- for(int i=0;i<a;i++){
, ]0 b8 s) Q, y - for(int l=i;l<a;l++){- h! @/ j `- N7 G
- System.out.print(" ");
. D+ X4 L/ B" F& v! y# e' Q - }7 l8 w& u$ h: h' {; W
- for(int j=a-i;j<=a;j++){' C" i" n# _1 d' S0 s
- System.out.print(num[i][a-j]+" ");
( c3 H5 D |7 l6 b7 h) c* x - }
7 M1 f2 q {1 d+ X4 |* j - System.out.println();
. h ]6 z1 I C - }
0 _/ S( @& Z( G& e( r% g5 z - }
+ z F! A1 d7 d/ y: O - }: J$ f/ c6 q; ]8 \
复制代码 |
|