Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import iut.algo.Clavier;
- /** Class Le triangle de Pascal
- * @author Monster
- * date : 18/11/2019
- */
- public class TP6_TrianglePascal
- {
- public static String Affichage (int[][] tab)
- {
- String retour;
- retour = "";
- for (int i=0;i<tab.length;i++)
- {
- retour = retour + i + ":";
- for(int j=0;j<tab[0].length;j++)
- {
- retour = retour + " ";
- if(tab[i][j]<10){retour = retour + " ";}
- if(tab[i][j] == 0){retour = retour + " ";}
- else {retour = retour + tab[i][j] + " ";}
- }
- retour = retour + "\n";
- }
- return retour;
- }
- public static void main(String[] a)
- {
- /*----------------------*/
- /* Données */
- /*----------------------*/
- final int TAILLE = 9;
- int[][] tabPascal;
- tabPascal = new int[TAILLE][TAILLE];
- int numLign=0, numCol=0;
- /*----------------------*/
- /* Remplir le tableau */
- /*----------------------*/
- for (int i=0; i<tabPascal.length; i++)
- {
- for (int j=0; j<tabPascal.length; j++)
- {
- tabPascal[i][j] = 0;
- }
- }
- /*----------------------*/
- /* Instructions */
- /*----------------------*/
- tabPascal[0][0]=1;
- for (int i=1; i<tabPascal.length; i++)
- {
- for (int j=0; j<tabPascal.length; j++)
- {
- if (j==0)
- {
- tabPascal[i][j] = tabPascal[i-1][j];
- }
- else
- {
- tabPascal[i][j] = tabPascal[i-1][j-1]+tabPascal[i-1][j];
- }
- }
- }
- /*----------------------*/
- /* Affichage */
- /*----------------------*/
- System.out.println(Affichage(tabPascal));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement