杨辉三角形
import java.util.Scanner; /** * 求杨辉三角第m层第n个数字 * @author Administrator * */ public class Demo05 { public static int f(int m,int n) { if(n==0)return 1; if(m==0 || m==n)return 1; return f(m-1,n-1)+f(m-1,n);//只需要写上规律语句即可 } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int m = sc.nextInt(); for(int i = 0;i<m+1;i++) { System.out.print(f(m,i)+" "); } //System.out.println(f(3,2)); } }