// write a code in java to print the pascals triangle for a given number of rows using a function import java.util.Scanner; class PascalsTriangle{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the number of rows: "); int rows = sc.nextInt(); System.out.println("Pascal's Triangle: "); // for(int i=0; i=0; j--){ if(j == 0 || j == i){ dp[j] = 1; }else{ dp[j] = dp[j-1] + dp[j]; } } // does not save the entire triangle, only the current row // its indented in the loop to print the triangle for(int j=0; j<=i; j++){ System.out.print(dp[j] + " "); } System.out.println(); } } }