Pascal's Triangle in java | Coding Startup

Pascal's Triangle in java

Pascal's Triangle in java.


100% Working Code and Projects.


if you need any help about project and Application Contact Shelly at:+917888361589.



Java Code Given Below:-



public class Pattern {

    public static void main(String[] Abheer) {
        int  abheer = 1;

        for(int i = 0; i <7; i++) {
            for(int space = 1; space < 7 - i; ++space) {
                System.out.print("  ");
            }

            for(int j = 0; j <= i; j++) {
                if (j == 0 || i == 0)
{
                    abheer = 1;
 }               else{
                    abheer = abheer * (i - j + 1) / j;
}
                System.out.printf("%4d", abheer);
            }

            System.out.println();
        }
    }
}

Output:-

               1
             1   1
           1   2   1
         1   3   3   1
       1   4   6   4   1
     1   5  10  10   5   1
   1   6  15  20  15   6   1


Code Startup

Author & Editor

0 Comments:

Post a Comment