SHARE
TWEET

Untitled

a guest Jul 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class PascalTriangle02 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner=new Scanner(System.in);
  6.  
  7.         int n=Integer.parseInt(scanner.nextLine());
  8.        
  9.         int[]numbers=new int[n];
  10.         int[]count=new int[n];
  11.  
  12.         int sum=0;
  13.         for (int rowls = 0; rowls <n ; rowls++) {
  14.             if (rowls==0||rowls==n-1){
  15.                 numbers[rowls]=1;
  16.                 count[rowls]=numbers[rowls];
  17.             }else{
  18.                 for (int i = 0; i <rowls ; i++) {
  19.                     if (i==0){
  20.                         count[rowls]=numbers[i];
  21.                     }else {
  22.                          count[rowls]=numbers[rowls]+numbers[rowls-1];
  23.  
  24.                     }
  25.                 }
  26.             }
  27.             for (int i = 0; i < count[rowls]; i++) {
  28.                 System.out.print(count[i]+ " ");
  29.             }
  30.  
  31.             System.out.println();
  32.         }
  33.     }
  34. }
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