Advertisement
Guest User

PROGRAM1

a guest
Mar 6th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class main {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.  
  8.         // Wprowadzanie liczb przez okna dialogowe
  9.     String txt; //deklaracja zmiennej tekstowej
  10.     txt = JOptionPane.showInputDialog("Liczba wierszy:");
  11.     int liczba = Integer.parseInt(txt);
  12.     System.out.println("liczba wierszy trojkata pascala to: " + liczba);   
  13.     int [][]tab=new int [liczba][liczba];
  14.     for (int i=0; i<tab.length; i++)
  15.     {  tab[i][0]=1;
  16.         for(int j=1; j<tab[i].length;j++)
  17.         {
  18.             if(j==i)
  19.             { tab[i][j]=1;}
  20.             else if(i>1 && j<liczba-1)
  21.             {
  22.                
  23.                 tab[i][j]=tab[i-1][j-1]+tab[i-1][j];
  24.             }
  25.            
  26.                
  27.         }
  28.     }
  29.     int wartosc=tab.length;
  30.     for (int i=0; i<tab.length; i++)
  31.     {  
  32.         for(int x=wartosc;x>0;x--)
  33.             {
  34.             System.out.print(" ");
  35.             }
  36.         for(int j=0; j<i+1;j++)
  37.             {
  38.             System.out.print(tab[i][j] + " ");         
  39.             }
  40.         System.out.println();
  41.         wartosc--;
  42.     }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement