Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class main {
- public static void main(String[] args) {
- // Wprowadzanie liczb przez okna dialogowe
- String txt; //deklaracja zmiennej tekstowej
- txt = JOptionPane.showInputDialog("Liczba wierszy:");
- int liczba = Integer.parseInt(txt);
- System.out.println("liczba wierszy trojkata pascala to: " + liczba);
- int [][]tab=new int [liczba][liczba];
- for (int i=0; i<tab.length; i++)
- { tab[i][0]=1;
- for(int j=1; j<tab[i].length;j++)
- {
- if(j==i)
- { tab[i][j]=1;}
- else if(i>1 && j<liczba-1)
- {
- tab[i][j]=tab[i-1][j-1]+tab[i-1][j];
- }
- }
- }
- int wartosc=tab.length;
- for (int i=0; i<tab.length; i++)
- {
- for(int x=wartosc;x>0;x--)
- {
- System.out.print(" ");
- }
- for(int j=0; j<i+1;j++)
- {
- System.out.print(tab[i][j] + " ");
- }
- System.out.println();
- wartosc--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement