Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Pyramid star pattern in java

class pyramid {
  // pyramid star pattern
  public static void main(String[] args) {

    int size = 5;
    for (int i = 0; i < size; i++) {
      // print spaces
      for (int j = 0; j < size - i - 1; j++) {
        System.out.print(" ");
      }
      // print stars
      for (int k = 0; k < 2 * i + 1; k++) {
        System.out.print("*");
      }
      System.out.println();
    }
  }
}
Comment

star pyramid program in java

public static void StarPyramid(int n)
{
    for (int i = 0; i < n; i++) 
    {
        var bol = true;
        for (int j = 0; j < 2*n; j++) 
        {
            if(j+i>=n && j<=n+i)
            {
                if(bol)System.out.print("*");
                else System.out.print(" ");
                bol=!bol;
            }
            else System.out.print(" ");
        }
        System.out.println();
    }
}
//for n =7
       *      
      * *     
     * * *    
    * * * *   
   * * * * *  
  * * * * * * 
 * * * * * * *
Comment

Hollow pyramid star pattern in java

class hollowPyramid {
  public static void main(String[] args) {
    // size of the pyramid
    int size = 5;
    for (int  i = 0; i < size; i++) {
      // print spaces
      for (int j = 0; j < size - i - 1; j++) {
        System.out.print(" ");
      }
      // print stars
      for (int k = 0; k < 2 * i + 1; k++) {
        if (i == 0 || i == size - 1) {
          System.out.print("*");
        }
        else {
          if (k == 0 || k == 2 * i) {
            System.out.print("*");
          }
          else {
            System.out.print(" ");
          }
        }
      }
      System.out.println();
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: mapping over a list of promises in javaascript 
Java :: java reverse string 
Java :: resize array in java 
Java :: sort comparator in java 
Java :: sc.nextline skips 
Java :: method reference in java 
Java :: java class jar determine 
Java :: android toast 
Java :: java memory increase command 
Java :: java instanceof keyword 
Java :: define an array of size n in java 
Java :: Java for and while loops 
Java :: set spring context 
Java :: function overriding java 
Java :: java iterate map and remove 
Java :: javafx arabic letters 
Java :: Error: Could not find or load main class javafx.controls,javafx.fxml Caused by: java.lang.ClassNotFoundException: javafx.controls,javafx.fxml 
Java :: how to use a combo box in java with if else 
Java :: export JAVA_HOME=` mac 
Java :: rider find and replace 
Java :: current time stamp android java 
Java :: java split string without removing 
Java :: spring boot swagger ui 401 
Java :: how to initialize a string in java 
Java :: how to sort arraylist 
Java :: java boucle for 
Java :: swiperefreshlayout 
Java :: como crear un array list en java 
Java :: scala vs java 
Java :: java string vers int 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =