|
- import java.util.*;: y% L T' [) [2 L4 G
) b4 G4 `2 r: V* y; R1 h/ b! U- public class Main{
- a7 ~! F" Y4 @" C -
$ P& _2 a- w* E7 `- M4 M - public static void main(String[] args) {
7 ?3 B/ ^6 U/ ?+ K* S! }; m5 \ - Scanner in=new Scanner(System.in);
% L# t; Q$ L% W - System.out.println("请输入行数");# m. k- { k: X& b$ p8 ]4 B% k2 I
- int a=in.nextInt();6 Y( h9 K4 N1 N Q. q
- int num[][] = new int[a][a];
8 d7 q, L4 E+ L: a2 N' Q - for(int m=0;m<a;m++){8 I# b# g+ `0 K- H/ G
- for(int n=0;n<=m;n++){8 f. K; r+ |: x
- if(n==0||m==n){3 V. [' f$ Q9 H/ X7 ~5 {6 _7 d' |" w6 h
- num[m][n]=1;) S$ m* V @! J6 ^" P
- }
% v6 K% n2 q% p, y' u" U9 q* h - else# ?2 K3 k3 P1 ]
- num[m][n]=num[m-1][n-1]+num[m-1][n];
7 Q& @, @' ], t( g; a ` - }3 `$ s0 l9 M. z1 o' v8 w
- }
3 u" P$ G7 b: G - for(int i=0;i<a;i++){6 x, q1 T- ~: Q! t$ @
- for(int l=i;l<a;l++){
$ w, A9 E* E+ l - System.out.print(" ");! [$ Z5 s3 p: U# F8 r
- }! c' o* D0 x H4 M% P7 _& M$ G! t
- for(int j=a-i;j<=a;j++){! Z& y& m8 g6 G ?; ~
- System.out.print(num[i][a-j]+" ");# N) \- A0 ?! n! `" K! w
- }
: ?2 Y" D! ?1 L: H( w) l/ j - System.out.println();
) E0 q. y+ B, a8 Q - } : _' g0 h7 i, R
- }
! u/ E$ U6 `8 J* M4 G - }. d6 B# w+ v. V) p7 q7 w& Q
复制代码 |
|