其实都一样和c语言 算法一摸一样
代码示例:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int a[][]=new int[100][100]; a[0][0]=0; a[1][0]=1; a[2][0]=1; a[2][1]=1; for (int i =3; i <=n; i++) { for (int j = 0; j <i; j++) { if(j==0||j==i-1) { a[i][j]=1; } else { a[i][j]=a[i-1][j]+a[i-1][j-1]; } } } for (int i = 1; i <=n; i++) { for(int j=0;j<i;j++) { System.out.printf("%-4d",a[i][j]); } System.out.println(); } } }