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

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 :: java finally block 
Java :: how to find lcm of two numbers java 
Java :: Java Scanner nextInt() 
Java :: java casting to int 
Java :: Java Create a Scanner Object in Java 
Java :: spring boot send api request 
Java :: how to close scanner in java 
Java :: Java Creating a HashSet 
Java :: Java Add elements to a HashMap 
Java :: java tree traversal 
Java :: create a string in java 
Java :: java startswith regex 
Java :: find minimum element in a sorted and rotated array 
Java :: insert node at end of doubly linked list 
Java :: spring login response data 
Java :: How to remove an element from a Java List? 
Java :: try catch in java 
Java :: set array length java 
Java :: playwright java 
Java :: jenkins password decrypt online 
Java :: kingkaihockey 
Java :: how to declare a variable when using loops Java 
Java :: varstatus foreach jsp 
Java :: coin flip random java 
Java :: java get first not null element 
Java :: android stop audio playing by activity lifecycle 
Java :: make new file in intellij for java 
Java :: viewresolver in spring boot 
Java :: sort colors 
Java :: lelen suratlari ramkasidagi oltinlar 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =