Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PascalTriangle {
- public static void main(String args[]) {
- int x = 10;
- int triangle[][] = new int[x][x];
- for (int i = 0; i < x; i++) {
- for (int j = 0; j < x; j++) {
- triangle[i][j] = 0;
- }
- }
- for(int i = 0; i < x; i++) {
- triangle[i][0] = 1 ;
- }
- for (int i = 1; i < x; i++) {
- for (int j = 1; j < x; j++) {
- triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j];
- }
- }
- for (int i = 0; i < x; i++) {
- for(int s=1; s<=x-i; s++) {
- System.out.print(" ");
- }
- for(int j=0;j<=i;j++) {
- System.out.printf("%4s", triangle[i][j]);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement