Java Program to Print Diamond Pattern of Star Character

Here is a java program to print a diamond pattern of start character using loop.


Java Program to Print Diamond Pattern of Star Character

package com.tcc.java.programs;

import java.util.*;

public class DiamondPattern {
    public static void main(String args[]) {
        int rows = 7, i, space, star = 0;
  
        // Printing upper triangle 
        for(i = 1; i <= rows; i++) {
            // Printing spaces 
            for(space = 1; space <= rows-i; space++) {
                System.out.print(" ");
            }
        
            // Printing stars 
            while(star != (2*i - 1)) {
                System.out.print("*");
                star++;
            }

            star=0;
            // move to next row 
            System.out.print("\n");
        }
        rows--;

        // Printing lower triangle 
        for(i = rows;i >= 1; i--) {
            // Printing spaces 
            for(space = 0; space <= rows-i; space++) {
                System.out.print(" ");
            }
         
            // Printing stars 
            star = 0;
            while(star != (2*i - 1)) {
                System.out.print("*");
                star++;
            }
            System.out.print("\n");
        }
    }
}
Output
      *
     ***
    *****
   *******
  *********
 ***********
*************
 ***********
  *********
   *******
    ***** 
     ***
      *

Recommended Posts
Java Program to Print Pyramid Pattern of Stars
Java Program to Print Right Triangle Star Pattern
Java Program to Print Pascal Triangle
Java program to Print Square Pattern of Star Character
Java Program to Print Multiplication Table Triangle Pattern
Java Program to Print Inverted Pyramid Pattern of Stars
Java Program to Print Right Triangle Pattern of Natural Numbers
Java Program to Print Inverted Right Triangle Star Pattern
Java Program to Check Whether two Strings are Equal or Not
Java Program to Delete a Word from Sentence
Java Program to Find Length of a String
All Java Programs