java pyramid pattern

Solutions on MaxInterview for java pyramid pattern by the best coders in the world

showing results for - "java pyramid pattern"
Jannik
20 Sep 2016
1import java.util.Scanner;
2public class Edureka
3{
4      
5public static void main(String[] args) 
6{
7Scanner sc = new Scanner(System.in);
8      
9System.out.println("Enter the number of rows: ");
10 
11int rows = sc.nextInt();
12          
13for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--)
14   {
15       System.out.print(j+" ");
16   }
17     
18   System.out.println();
19}         
20sc.close();
21}
22}
23
Paula
29 Sep 2020
1
2        1
3      2 3 2
4    3 4 5 4 3
5  4 5 6 7 6 5 4
65 6 7 8 9 8 7 6 5
Caterina
27 Jan 2018
1public class Main {
2
3  public static void main(String[] args) {
4    int rows = 5, k = 0, count = 0, count1 = 0;
5
6    for (int i = 1; i <= rows; ++i) {
7      for (int space = 1; space <= rows - i; ++space) {
8        System.out.print("  ");
9        ++count;
10      }
11
12      while (k != 2 * i - 1) {
13        if (count <= rows - 1) {
14          System.out.print((i + k) + " ");
15          ++count;
16        } else {
17          ++count1;
18          System.out.print((i + k - 2 * count1) + " ");
19        }
20
21        ++k;
22      }
23      count1 = count = k = 0;
24
25      System.out.println();
26    }
27  }
28}
Brook
09 Oct 2017
1// Java implementation to print the 
2// following pyramid pattern 
3public class Pyramid_Pattern { 
4  
5    // function to print the following pyramid 
6    // pattern 
7    static void printPattern(int n) 
8    { 
9        int j, k = 0; 
10  
11        // loop to decide the row number 
12        for (int i = 1; i <= n; i++) { 
13              
14            // if row number is odd 
15            if (i % 2 != 0) { 
16              
17                // print numbers with the '*'  
18                // sign in increasing order 
19                for (j = k + 1; j < k + i; j++) 
20                    System.out.print(j + "*"); 
21                System.out.println(j++); 
22  
23                // update value of 'k' 
24                k = j; 
25            } 
26  
27            // if row number is even 
28            else { 
29                 
30                // update value of 'k' 
31                k = k + i - 1; 
32  
33                // print numbers with the '*' in 
34                // decreasing order 
35                for (j = k; j > k - i + 1; j--) 
36                    System.out.print(j + "*"); 
37                System.out.println(j); 
38            } 
39        } 
40    } 
41  
42    // Driver program to test above 
43public static void main(String args[]) 
44    { 
45        int n = 5; 
46        printPattern(n); 
47    } 
48} 
queries leading to this page
pyramid with javapyramid of stars in javajava program of pyramid numberpyramid number pattern in javastring pyramid pattern in javapyramid in javanested loop pattern questionsprogram to print pyramid using 2a in javajava pyramid programspyramid output in javapyramid pattern in javadisplay pyramid in javapyramid pattern in java logicpyramid of asetricks in javapyramid pattern program in javapyramid printing and return in a string javahow to make a pyramid of asterisks in javajava program pyramid pattern number pyramid pattern of number in javajava print pyramidprint string pyramid in javapyramid and reverse pyramid star pattern in javapyramid using numbers in javapyramid java programnumber pattern pyramid in java logicnested for loop to print the pyramid in javahow to make string pyramid javaprogram makes a pyramid of great pyramid in javastring traversal in pyramid format in javajava program pyramid pattern number tutorialspointnormal pyramid in javahow to create pyramid in javapyramid number pattern javaprint pyramid pattern in javajava for loop pyramida java program to print pyramid pattern with loopsstring traversal in pyramid in javamake pyramid in javapyramid print in javajava print 2a pyramidprinting pyramid patterns in javahow to print pyramid in java 2a pyramid in javapyramid pattern printing program in javapyramid javawrite a program to print the following patterns using loops a 29 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1print pyramid of a string in javacreate a pyramid in javaprint a pyramid in javastar pyramid pattern in javaleft and right pyramid pattern in javaprinting pyramid in javapyramid printing in javalogic to print pyramid of stars in javaprinting numbers in a pyramid pattern in javahow to print a pyramid in javawrite a program to print the following pattern pyramid 1 27 in javawrite piramid numbers javapyramid pattern in java gfgpyramid shape pattern javaprint pyramid in javaprint reverse pyramid in javahow to write a triangle for javafor loop pyramid javadesign pattern in javajava program to print pyramid pattern of starsfull pyramid pattern in javacreate triangle in javajava pyramid patternpyramides javawrite a pyramid program in javahow to make pyramid pattern in javastream pyramid pattern in javahow to make pyramid pattern in java using threadspyramid program in javapyramid 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a javahow to print full pyramid in javajava pyramid programjava intervted pyramid patternhow to print 1 2 1 3 2 1 4 3 2 1 3 2 1 2 1 1 pyramidcharacter pyramid pattern in javahow to get a pyramid in javapyramid problem javapyramid program in java with explanationcode to print pyramid in javajava number pyramidpyramid program in java using while looplogic to print patterns in javapyramid pattern loop in javajava pyramid patternsstring name pyramid pattern in javajava program to print pyramid how to code a pyramid in javacode to print pyramid of number in javapyramid star pattern in javahow to make a pyramid in javapatterns in javajava pyramidstar pyramid in javastring traversal in pyramid pattern in javareverse pyramid pattern in javapyramid triangle javadesign pattern javastart left or right pyramid in javahow to get pyramid pattern in javapyramid star patten in javajava pyramid pattern