Guest User

Untitled

a guest
Jan 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pascal {
  4. public static void main(String[] args) {
  5.  
  6. Scanner inputk = new Scanner(System.in);
  7. int n = 0;
  8.  
  9. do {
  10. System.out.println("Entrez un entier >= 1 ");
  11. n = inputk.nextInt();
  12. } while (n < 1);
  13.  
  14. int[][] tableau, tableau2;
  15. tableau = new int[1][1];
  16. for (int i = 0; i < n; i++) {
  17. tableau2 = new int[tableau.length][tableau.length];
  18. tableau2 = tableau;
  19. tableau = new int[i+1][i+1];
  20. for (int j = 0; j < (i+1); j++) {
  21. if (j == 0 || j == i || i == 0) {
  22. tableau[i][j] = 1;
  23. } else {
  24. tableau[i][j] = tableau2[i-1][j-1] + tableau2[i-1][j];
  25. }
  26.  
  27. }
  28.  
  29. //affichage
  30.  
  31. for (int k = 0; k < (i+1); k++) {
  32. System.out.print(tableau[i][k] + " ");
  33. }
  34. System.out.println();
  35. }
  36. }
  37.  
  38. }
Add Comment
Please, Sign In to add comment