print the following pattern using Java programming,
PYRAMID FORM ONLY...
Attachments:
TreeshaBiswas:
please anyone helpppp
Answers
Answered by
6
Required Answer:-
Question:
Write a Java program for the pattern.
*
* *
* * *
* * * *
Solution:
Here is the code.
- public class PatternBrainly {
- public static void main(String[] args) {
- int n=4;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n-i;j++)
- System.out.print(" ");
- for(int j=1;j<=i;j++)
- System.out.print(" *");
- System.out.println();
- }
- }
- }
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