File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed
Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * To change this license header, choose License Headers in Project Properties.
3+ * To change this template file, choose Tools | Templates
4+ * and open the template in the editor.
5+ */
6+ package recursion ;
7+
8+ /**
9+ * @date 09/01/19
10+ * @author SPREEHA DUTTA
11+ */
12+ import java .util .*;
13+ public class PascalTriangle {
14+ public static int pascal (int r ,int c )
15+ {
16+ if (r ==c || c ==0 )
17+ return 1 ;
18+ else
19+ return pascal (r -1 ,c )+pascal (r -1 ,c -1 );
20+ }
21+ public static void print (int n )
22+ {
23+ for (int i =0 ;i <n ;i ++)
24+ {
25+ for (int j =0 ;j <=i ;j ++)
26+ System .out .print (pascal (i ,j )+" " );
27+ System .out .println ();
28+ }
29+ }
30+ public static void main (String []args )
31+ {
32+ Scanner sc =new Scanner (System .in );
33+ int n ;
34+ n =sc .nextInt ();
35+ print (n );
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -216,5 +216,41 @@ def main():
216216 print (f' Pascal triangle cannot have {num} rows' )
217217
218218main()
219+ ```
220+
221+ ## Java Implementation
222+
223+ ### [ Solution] ( ./Java/PascalTriangle.java )
219224
225+ ``` java
226+ /**
227+ * @date 09/01/19
228+ * @author SPREEHA DUTTA
229+ */
230+ import java.util.* ;
231+ public class PascalTriangle {
232+ public static int pascal (int r ,int c )
233+ {
234+ if (r== c || c== 0 )
235+ return 1 ;
236+ else
237+ return pascal(r- 1 ,c)+ pascal(r- 1 ,c- 1 );
238+ }
239+ public static void print (int n )
240+ {
241+ for (int i= 0 ;i< n;i++ )
242+ {
243+ for (int j= 0 ;j<= i;j++ )
244+ System . out. print(pascal(i,j)+ " " );
245+ System . out. println();
246+ }
247+ }
248+ public static void main (String []args )
249+ {
250+ Scanner sc= new Scanner (System . in);
251+ int n;
252+ n= sc. nextInt();
253+ print(n);
254+ }
255+ }
220256```
You can’t perform that action at this time.
0 commit comments