Java Program to Print Inverted V Star Pattern

Write a Java program to print inverted V star pattern or half diamond inside a square star pattern using for loop.

package Shapes3;

import java.util.Scanner;

public class InvertedVStarPattern1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Inverted V Shape Star Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Inverted V Shape Star Pattern");
		
		for (int i = rows; i >= 1; i-- ) 
		{
			for (int j = 1 ; j <= i; j++ ) 
			{
				System.out.print("*");

			}
			for (int k = 1 ; k <= 2 * (rows - i); k++ ) 
			{
				System.out.print(" ");
			}
			for (int l = 1 ; l <= i; l++ ) 
			{
				System.out.print("*");
			}
			System.out.println();
		}
	}
}
Java Program to Print Inverted V Star Pattern

This Java program displays the inverted V star pattern of stars using a while loop.

package Shapes3;

import java.util.Scanner;

public class InvertedVStarPattern2 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Inverted V Shape Star Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Inverted V Shape Star Pattern");
		
		int i = rows;
		while( i >= 1) 
		{
			int j = 1 ;
			while( j <= i ) 
			{
				System.out.print("*");
				j++;

			}
			int k = 1 ;
			while( k <= 2 * (rows - i) ) 
			{
				System.out.print(" ");
				k++;
			}
			int l = 1 ;
			while( l <= i ) 
			{
				System.out.print("*");
				l++;
			}
			System.out.println();
			i--;
		}
	}
}
Enter Inverted V Shape Star Pattern Rows = 13
Printing Inverted V Shape Star Pattern
**************************
************  ************
***********    ***********
**********      **********
*********        *********
********          ********
*******            *******
******              ******
*****                *****
****                  ****
***                    ***
**                      **
*                        *

Java Program to Print Inverted V Star Pattern using a do while loop

package Shapes3;

import java.util.Scanner;

public class InvertedVStarPattern3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Inverted V Shape Star Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Inverted V Shape Star Pattern");
		
		int i = rows;
		do 
		{
			int j = 1 ;
			do
			{
				System.out.print("*");

			} while( ++j <= i );
			int k = 1 ;
			while(k <= 2 * (rows - i))
			{
				System.out.print(" ");
				k++;
			}
			int l = 1 ;
			do
			{
				System.out.print("*");
			} while( ++l <= i ) ;
			System.out.println();
		} while(--i >= 1);
	}
}
Enter Inverted V Shape Star Pattern Rows = 15
Printing Inverted V Shape Star Pattern
******************************
**************  **************
*************    *************
************      ************
***********        ***********
**********          **********
*********            *********
********              ********
*******                *******
******                  ******
*****                    *****
****                      ****
***                        ***
**                          **
*                            *

In this Java pattern example, InvertedVShapePattern function allows to enter any character and prints the inverted V of a given character.

package Shapes3;

import java.util.Scanner;

public class InvertedVStarPattern4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Inverted V Shape Star Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.print("Enter Character for Inverted V Pattern = ");
		char ch = sc.next().charAt(0);
		
		System.out.println("Printing Inverted V Shape Star Pattern");	
		InvertedVShapePattern(rows, ch);
	}
	public static void InvertedVShapePattern(int rows, char ch) 
	{
		for (int i = rows; i >= 1; i-- ) 
		{
			for (int j = 1 ; j <= i; j++ ) 
			{
				System.out.print(ch);

			}
			for (int k = 1 ; k <= 2 * (rows - i); k++ ) 
			{
				System.out.print(" ");
			}
			for (int l = 1 ; l <= i; l++ ) 
			{
				System.out.print(ch);
			}
			System.out.println();
		}	
	}
}
Enter Inverted V Shape Star Pattern Rows = 17
Enter Character for Inverted V Pattern = #
Printing Inverted V Shape Star Pattern
##################################
################  ################
###############    ###############
##############      ##############
#############        #############
############          ############
###########            ###########
##########              ##########
#########                #########
########                  ########
#######                    #######
######                      ######
#####                        #####
####                          ####
###                            ###
##                              ##
#                                #

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.