Computer Science, asked by TreeshaBiswas, 3 months ago

print the following pattern using Java programming,
PYRAMID FORM ONLY...

Attachments:

TreeshaBiswas: please anyone helpppp

Answers

Answered by anindyaadhikari13
6

Required Answer:-

Question:

Write a Java program for the pattern.

*

* *

* * *

* * * *

Solution:

Here is the code.

  1. public class PatternBrainly {
  2. public static void main(String[] args) {
  3. int n=4;
  4. for(int i=1;i<=n;i++)
  5. {
  6. for(int j=1;j<=n-i;j++)
  7. System.out.print(" ");
  8. for(int j=1;j<=i;j++)
  9. System.out.print(" *");
  10. System.out.println();
  11. }
  12. }
  13. }

Explanation:

  • We have divided the pattern into two parts, spaces and stars.
  • For the first part, we will print spaces. There are 3 spaces in the first line, 2 in the second and so on. So, the number of spaces is decreasing.
  • Mathematically, the number of spaces in each row for this pattern is n - i, where n is the total number of rows and i is the row number.
  • After printing the spaces, we will print stars.

Output is attached.

Attachments:
Similar questions