SHARE
TWEET

pascal

a guest Jul 19th, 2019 61 in 143 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Programming_Fundamentals.Arrays.Arrays_More_Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class E02PascalTriangle {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         int n = Integer.parseInt(sc.nextLine());
  9.         int[] arHelp = new int[n];
  10.  
  11.         for (int i = 1; i <= n ; i++) {
  12.  
  13.             int[] arNew = new int[i];
  14.             arNew[0] = 1;
  15.             arNew[arNew.length - 1] = 1;
  16.  
  17.             if (arNew.length > 2) {
  18.  
  19.                 for (int j = 1; j < arNew.length - 1 ; j++) {
  20.  
  21.                     arNew[j] = arHelp[j - 1] + arHelp[j];
  22.                 }
  23.             }
  24.             arHelp = arNew;
  25.  
  26.             for (int num : arNew) {
  27.                 System.out.print(num + " ");
  28.             }
  29.             System.out.println();
  30.         }
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top