Java Program to Print Hollow Rhombus Star Pattern

Write a Java Program to print hollow rhombus star pattern using for loop. This Java hollow rhombus example uses two for loops nested inside a for loop to traverse the rhombus rows. Within the second for loop, the if statement checks whether it is the first or last row and column to print the hollow rhombus.

package ShapePrograms;

import java.util.Scanner;

public class HollowRhombus1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Rhombus Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Hollow Rhombus Star Pattern");
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= rows - i; j++ ) 
			{
				System.out.print(" ");
			}
			for (int k = 1 ; k <= rows; k++ ) 
			{
				if (i == 1 || i == rows || k == 1 || k == rows) {
					System.out.print("* ");
				}
				else {
					System.out.print("  ");
				}
			}
			System.out.println();
		}
	}
}
Java Program to Print Hollow Rhombus Star Pattern 1

In this Java hollow rhombus star pattern program, we replaced the for loop with nested while loops.

package ShapePrograms;

import java.util.Scanner;

public class HollowRhombus2 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Rhombus Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Hollow Rhombus Star Pattern");
		int i = 1, j, k ;
		
		while ( i <= rows ) 
		{
			j = 1 ;
			while( j <= rows - i ) 
			{
				System.out.print(" ");
				j++;
			}
			k = 1 ;
			while ( k <= rows) 
			{
				if (i == 1 || i == rows || k == 1 || k == rows) {
					System.out.print("* ");
				}
				else {
					System.out.print("  ");
				}
				k++ ;
			}
			System.out.println();
			i++;
		}
	}
}
Enter Hollow Rhombus Pattern Rows = 10
Printing Hollow Rhombus Star Pattern
         * * * * * * * * * * 
        *                 * 
       *                 * 
      *                 * 
     *                 * 
    *                 * 
   *                 * 
  *                 * 
 *                 * 
* * * * * * * * * * 

Java Program to Print Hollow Rhombus Star Pattern using do while loop

package ShapePrograms;

import java.util.Scanner;

public class HollowRhombus3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Rhombus Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Hollow Rhombus Star Pattern");
		int i = 1, j, k ;
		
		do
		{
			j = 1 ;
			do
			{
				System.out.print(" ");
			} while( j++ <= rows - i ) ;
			k = 1 ;
			do 
			{
				if (i == 1 || i == rows || k == 1 || k == rows) {
					System.out.print("*");
				}
				else {
					System.out.print(" ");
				}
			} while ( ++k <= rows);
			System.out.println();
		} while ( ++i <= rows ) ;
	}
}
Enter Hollow Rhombus Pattern Rows = 14
Printing Hollow Rhombus Star Pattern
              **************
             *            *
            *            *
           *            *
          *            *
         *            *
        *            *
       *            *
      *            *
     *            *
    *            *
   *            *
  *            *
 **************

In this Java example, the hollowRhombusPattern function prints the hollow rhombus pattern of a given symbol.

package ShapePrograms;

import java.util.Scanner;

public class HollowRhombus4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Rhombus Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.print("Enter Character for Hollow Rhombus Pattern = ");
		char ch = sc.next().charAt(0);
		
		System.out.println("Printing Hollow Rhombus Star Pattern");
		hollowRhombusPattern(rows, ch);	
	}
	
	public static void hollowRhombusPattern(int rows, char ch) {
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= rows - i; j++ ) 
			{
				System.out.print(" ");
			}
			for (int k = 1 ; k <= rows; k++ ) 
			{
				if (i == 1 || i == rows || k == 1 || k == rows) {
					System.out.print(ch);
				}
				else {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}
Enter Hollow Rhombus Pattern Rows = 15
Enter Character for Hollow Rhombus Pattern = $
Printing Hollow Rhombus Star Pattern
              $$$$$$$$$$$$$$$
             $             $
            $             $
           $             $
          $             $
         $             $
        $             $
       $             $
      $             $
     $             $
    $             $
   $             $
  $             $
 $             $
$$$$$$$$$$$$$$$