import java. util. Scanner ;
public class a1 {
public static void main ( String [ ] args) {
Scanner myScanner = new Scanner ( System . in) ;
System . out. println ( "请输入杨辉三角的层数" ) ;
int length = myScanner. nextInt ( ) ;
int [ ] [ ] arr = new int [ length] [ ] ;
for ( int i = 0 ; i < arr. length; i++ ) {
arr[ i] = new int [ i + 1 ] ;
for ( int j = 0 ; j < arr[ i] . length; j++ ) {
if ( j != 0 && j != arr[ i] . length - 1 ) {
arr[ i] [ j] = arr[ i - 1 ] [ j] + arr[ i - 1 ] [ j - 1 ] ;
}
else {
arr[ i] [ j] = 1 ;
}
System . out. print ( arr[ i] [ j] + "\t" ) ;
}
System . out. println ( ) ;
}
}
}
import java. util. Scanner ;
public class a1 {
public static void main ( String [ ] args) {
Scanner myScanner = new Scanner ( System . in) ;
int length;
do {
System . out. println ( "请输入杨辉三角的层数(<= 16)" ) ;
length = myScanner. nextInt ( ) ;
if ( length > 16 ) {
System . out. println ( "层数太多,维持不了三角形" ) ;
}
else if ( length == 0 ) {
System . out. println ( "层数为0,请重新输入" ) ;
}
else {
break ;
}
} while ( true ) ;
int [ ] [ ] arr = new int [ length] [ ] ;
for ( int i = 0 ; i < arr. length; i++ ) {
arr[ i] = new int [ i + 1 ] ;
for ( int k = 0 ; k < arr. length - i - 1 ; k++ ) {
System . out. print ( " " ) ;
}
for ( int j = 0 ; j < arr[ i] . length; j++ ) {
if ( j != 0 && j != arr[ i] . length - 1 ) {
arr[ i] [ j] = arr[ i - 1 ] [ j] + arr[ i - 1 ] [ j - 1 ] ;
}
else {
arr[ i] [ j] = 1 ;
}
if ( i > 9 && j == 2 ) {
System . out. print ( arr[ i] [ j] + " " ) ;
}
else if ( i > 14 && j == 3 ) {
System . out. print ( arr[ i] [ j] + " " ) ;
}
else if ( arr[ i] [ j] >= 1000 ) {
System . out. print ( arr[ i] [ j] + " " ) ;
}
else if ( arr[ i] [ j] >= 100 ) {
System . out. print ( arr[ i] [ j] + " " ) ;
}
else if ( arr[ i] [ j] >= 10 && j <= arr[ i] . length - 3 ) {
System . out. print ( arr[ i] [ j] + " " ) ;
}
else {
System . out. print ( arr[ i] [ j] + " " ) ;
}
}
System . out. println ( ) ;
}
}
}