Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pascal {
- public static void main(String[] args) {
- Scanner inputk = new Scanner(System.in);
- int n = 0;
- do {
- System.out.println("Entrez un entier >= 1 ");
- n = inputk.nextInt();
- } while (n < 1);
- int[][] tableau, tableau2;
- tableau = new int[1][1];
- for (int i = 0; i < n; i++) {
- tableau2 = new int[tableau.length][tableau.length];
- tableau2 = tableau;
- tableau = new int[i+1][i+1];
- for (int j = 0; j < (i+1); j++) {
- if (j == 0 || j == i || i == 0) {
- tableau[i][j] = 1;
- } else {
- tableau[i][j] = tableau2[i-1][j-1] + tableau2[i-1][j];
- }
- }
- //affichage
- for (int k = 0; k < (i+1); k++) {
- System.out.print(tableau[i][k] + " ");
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment