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

Pyramid pattern program in java

// pyramid pattern - TutorialsTonight

public 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();
    }
  }
}
/* Output:
    *
   ***
  *****
 *******
*********

*/
Comment

pyramid pattern java

import java.io.*;
 
// Java code to demonstrate star pattern
public class GeeksForGeeks
{
    // Function to demonstrate printing pattern
    public static void printNums(int n)
    {
        // initialising starting number
        int i, j, num=1;
         
        // outer loop to handle number of rows
        // n in this case
        for(i=0; i<n; i++)
        {
 
            // without re assigning num
            // num = 1;
            for(j=0; j<=i; j++)
            {
                // printing num with a space
                System.out.print(num+ " ");
                 
                // incrementing num at each column
                num = num + 1;
            }
 
            // ending line after each row
            System.out.println();
        }
    }
     
    // Driver Function
    public static void main(String args[])
    {
        int n = 5;
        printNums(n);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to remove all characters before a certain character from a string in java 
Java :: what does setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) is used for 
Java :: use regex in if statement java 
Java :: synchronized block java 
Java :: how to make a dictionary in java 
Java :: pre increment and post increments java 
Java :: press enter in robot java 
Java :: java String revers 
Java :: java string literals 
Java :: declaration and definition of array in java 
Java :: abstraction in java 
Java :: spring boot dockerfile 
Java :: java arrayList of array to array of array 
Java :: equals ignore case java 
Java :: remove duplicate from string 
Java :: What is the way to use profiles to configure the environment-specific configuration with Spring Boot? 
Java :: java list get first element 
Java :: jdk 15 download brew 
Java :: enum values to string array 
Java :: java check if property exists in class 
Java :: android studio setBackground 
Java :: java list last element 
Java :: spring 5 jdbctemplate query for a single value 
Java :: initialize hashmap java 
Java :: how to output in java 
Java :: lowercase string java 
Java :: java check if string contains multiple words 
Java :: android convert date to local timezone 
Java :: flutter unable to find bundled java version 
Java :: How to summon an item in bukkit 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =