Write a program in Java to print Pascal's triangle
Answers
Answered by
3
/* Java Program Example - Print Pascal Triangle */
import java.util.Scanner;
public class JavaPascalTriangle
{
public static void main(String args[])
{
int r, i, k, number=1, j;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Number of Rows : ");
r = scan.nextInt();
for(i=0;i<r;i++)
{
for(k=r; k>i; k--)
{
System.out.print(" ");
}
number = 1;
for(j=0;j<=i;j++)
{
System.out.print(number+ " ");
number = number * (i - j) / (j + 1);
}
System.out.println();
}
}
}
I hope this answer help to you
import java.util.Scanner;
public class JavaPascalTriangle
{
public static void main(String args[])
{
int r, i, k, number=1, j;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Number of Rows : ");
r = scan.nextInt();
for(i=0;i<r;i++)
{
for(k=r; k>i; k--)
{
System.out.print(" ");
}
number = 1;
for(j=0;j<=i;j++)
{
System.out.print(number+ " ");
number = number * (i - j) / (j + 1);
}
System.out.println();
}
}
}
I hope this answer help to you
Nik7117:
thanks didi
Similar questions