Find the Nth row in Pascal 's Triangle | Java Program to find the Nth index row in Pascal 's triangle ; Function to find the elements of rowIndex in Pascal 's Triangle ; 1 st element of every row is 1 ; Check if the row that has to be returned is the first row ; Generate the previous row ; Generate the elements of the current row by the help of the previous row ; Return the row ; Driver Program
import java . util . ArrayList ; public class geeks { public static ArrayList < Integer > getRow ( int rowIndex ) { ArrayList < Integer > currow = new ArrayList < Integer > ( ) ; currow . add ( 1 ) ; if ( rowIndex == 0 ) { return currow ; } ArrayList < Integer > prev = getRow ( rowIndex - 1 ) ; for ( int i = 1 ; i < prev . size ( ) ; i ++ ) { int curr = prev . get ( i - 1 ) + prev . get ( i ) ; currow . add ( curr ) ; } currow . add ( 1 ) ; return currow ; } public static void main ( String [ ] args ) { int n = 3 ; ArrayList < Integer > arr = getRow ( n ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( i == arr . size ( ) - 1 ) System . out . print ( arr . get ( i ) ) ; else System . out . print ( arr . get ( i ) + " , ▁ " ) ; } } }