lease provide the UML digaram for the following code below***
***Please provide the UML digaram for the following code below***
PROGRAM CODE:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int rows = sc.nextInt();
System.out.println("Pascal Triangle for row: "+rows);
printTriangle(rows);
sc.close();
}
public static void printTriangle(int n)
{
for (int i = 0; i < n; i++)
{
for (int k = 0; k < n - i; k++)
{
System.out.print(" "); // print space for display like triangle
}
for (int j = 0; j <= i; j++)
{
System.out.print(pascal(i, j) + " ");
}
System.out.println();
}
}
public static int pascal(int i, int j)
{
if (j == 0 || j == i)
{
return 1;
}
else
{
return pascal(i - 1, j - 1) + pascal(i - 1, j);
}
}
}
Step by step
Solved in 2 steps with 1 images