Geography, asked by TreeshaBiswas, 3 months ago

print the following pattern using Java programming
PYRAMID FORM..

1 121 12321 1234321.


chopadeom9011: hii
chopadeom9011: hi

Answers

Answered by vaishnavi1585
66

from this method you can print following pattern

Explanation:

public class Pyramid

{

public static void main(String[] args)

{

int i=0,j=0,n=6,k=0;

for(i=0; i<n; i++)

{

k=1;

for(j=0; j<(n+i); j++)

{

if(j<n-i-1)

System.out.print(" ");

else

{

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

if(j<(n-1))

k++;

else

k--;

}

}

System.out.println(" ");

}

}

}

OUTPUT

1

121

12321

1234321

123454321

12345654321


TreeshaBiswas: thanks a lot
vaishnavi1585: it's okar
moin3044: which programming software do you use
BrainlyEmpire: Good!
Anonymous: Great ✌
Answered by allysia
81

Program:

import java.util.Scanner;

public class oh { public static void main(String[] args)

{ Scanner scan= new Scanner (System.in);

System.out.print("Enter the highest number: ");

 int n=scan.nextInt();

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

for (int k=1; k<n+1-i; k++)  {System.out.print(" ");}

for (int k=1; k<i+1; k++)  {System.out.print(k);}

for (int k=i-1; k>0; k-=1)  {System.out.print(k);}

 System.out.println();}

} }

Explanation for what I did:

  1. Took n as input.
  2. Used a main for loop to control output per line.
  3. Let 1st nested for loop control spaces.
  4. Let 2nd nested loop control numbers till highest number per line (1,12,123 and so on).
  5. Let 3rd nested loop print till 2nd highest number in each line in reverse (1,21,321 etc).

Note: consider the attachment for output and program in IDE.

Attachments:

AbhinavRocks10: PERFECT ANSWER⚡
QueenOfStars: Splendid! :D
Anonymous: Love love xD
Anonymous: Marvellous ✌
BrainlyProgrammer: Gr8 Answer
Anonymous: Indian Khiladi here
Anonymous: xD xD
Similar questions