SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | ||
| 3 | public class Pascal{
| |
| 4 | public static void main(String[] args){
| |
| 5 | Scanner console = new Scanner(System.in); | |
| 6 | int n = console.nextInt(); | |
| 7 | for (int i = 1; i<=n; i++){
| |
| 8 | for (int x = 1; x <= 2*(n)-2*i; x++) {
| |
| 9 | System.out.print(" ");
| |
| 10 | } | |
| 11 | for (int r=0; r<=i-1; r++) {
| |
| 12 | long c = fact(i-1)/(fact(i-1-r)*fact(r)); | |
| 13 | System.out.printf("%-4d",c);
| |
| 14 | } | |
| 15 | System.out.println(); | |
| 16 | } | |
| 17 | } | |
| 18 | public static long fact(int n){
| |
| 19 | long f=1; | |
| 20 | for(int i=n;i>=1;i--) {
| |
| 21 | f*=i; | |
| 22 | } | |
| 23 | return f; | |
| 24 | } | |
| 25 | } |