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