Computer Science, asked by Prakhar112332, 1 year ago

Print this pattern in java
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Answers

Answered by manitkartik297
0

public class Pattern {

   public static void main(String[] args) {

       int rows = 5;

       for(int i = 1; i <= rows; ++i) {

           for(int j = 1; j <= i; ++j) {

               System.out.print("* ");

           }

           System.out.println();

       }

   }

}


Prakhar112332: Sorry but I asked for
Prakhar112332: Spaces also
Prakhar112332: Let it be
Prakhar112332: Sorry but is printing
Prakhar112332: I asked for
Answered by sushanpoudel044
0

Answer:

public class pattern16 {

   public static void main(String[] args) {

       int n = 5, val = 1;

       for (int row = 0; row < n; row++) {

           for (int spaces = 1; spaces <= n - row; spaces++) {

               System.out.print(" ");

           }

           for (int col = 0; col <= row; col++) {

               if (col == 0 || row == n)

                   System.out.print("1");

               else

                   System.out.print(" " + (val = val * (row - col + 1) / col));

           }

           System.out.println("");

       }

   }

}

Explanation:

Similar questions