Computer Science, asked by TreeshaBiswas, 4 months ago

print the following pattern using java programming,
PYRAMID FORM...

*
* *
* * *
* * * *​

Answers

Answered by rajesh205
1

Explanation:

public class Main {

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();

}

}

}

Example 2: Program to print half pyramid a using numbers

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

Source Code

public class Main {

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(j + " ");

}

System.out.println();

}

}

}

Example 3: Program to print half pyramid using alphabets

A

B B

C C C

D D D D

E E E E E

Source Code

public class Main {

public static void main(String[] args) {

char last = 'E', alphabet = 'A';

for (int i = 1; i <= (last - 'A' + 1); ++i) {

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

System.out.print(alphabet + " ");

}

++alphabet;

System.out.println();

}

}

}

Programs to print inverted half pyramid using * and numbers


TreeshaBiswas: is the first answer in pyramid form??
rajesh205: ooo
Answered by BrainlyProgrammer
5

As it is mentioned Pyramid form....The correct pattern is given below

 \:  \:  \: * \\  \:  \: * \:  \: \:  \:  \:  \:  \:   \: * \\ * \:    \:  \:  \: \: \:  \: * \:  \:   \:  \:  \:  \:  \: * \\ * \:  \:  \:  \:  \:  \:  \:  \:  \:  \: * \:  \:  \:  \:  \:  \:  \: * \:  \:  \:  \:  \:  \: *

Code Language:-

  • Java

Code:-

package Coder;

public class PyramidStarPatt

{

public static void main (String ar [])

{

for(int i=1;i<4;i++)

{

for(int j=4;j>i;j--)

{

System.out.print(" "); //This loop prints the spaces

}

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

{

System.out.print("* ");

//This loop prints asterisk(*) with spaces

}

System.out.println(); //To leave lines

}

}

}

Variable Description:-

  1. i:- loop variable
  2. j:- Loop variable

Similar questions