# Java Program to Print Right Pascal and Left Pascal Triangle Face to Face (Butterfly) Star Pattern

## Program to Print Butterfly Star Pattern

In this article we are going to see how to print the Reverse k-shape star program.

Example-1

When row value=4
*         *
**      **
***   ***
********
***   ***
**      **
*         *
Example-2:

When row value=5
*            *
**         **
***      ***
****   ****
**********
****   ****
***      ***
**         **
*           *

Now, let’s see program to  how print it.

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

Approach:

• Enter total row and store it in an integer variable row.
• Take first outer for loop to print all rows of upper part .
• First inner for loop will print all stars of the column of the left pascal.
• Second inner loop will print the space of all column value .
• Third  inner for loop to print all stars of the column values of right pascal .
• Take first outer for loop to print all rows of lower part .
• First inner for loop will print all stars of the column of the left pascal.
• Second inner loop will print the space of all column value .
• Third  inner for loop to print all stars of the column values of right pascal .

JAVA Code:

### Method-1 : Static Star Character

import java.util.*;
public class Main
{
public static void main(String args[])
{
// taking variable for loop iteration and row .
int row,r,c,d;
//creating object
Scanner s = new Scanner(System.in);
// entering the number of row
System.out.print("Enter rows : ");
row = s.nextInt();
//printing row value (upper part )
for (r=1; r<=row ; r++)
{
for (c = 1; c <= r; c++)
System.out.print("*");
for (c= r*2; c <= row*2-1; c++)
System.out.print(" ");
for (c = 1; c <= r; c++)
System.out.print("*");
System.out.println();
}
//printing row value (lower part )
for (r=1; r<=row -1; r++)
{
for (c = row -1; c >= r; c--)
System.out.print("*");
for (c= 1; c <= r*2; c++)
System.out.print(" ");
for (c = row -1; c >= r; c--)
System.out.print("*");
System.out.println();
}
}
}

Output:

Enter Rows :5
*            *
**         **
***      ***
****   ****
**********
****   ****
***      ***
**         **
*            *

### Method-2 : User Input Character

import java.util.*;
public class Main
{
public static void main(String args[])
{
// taking variable for loop iteration and row .
int row,r,c,d;
char k;
//creating object
Scanner s = new Scanner(System.in);
// entering the number of row
System.out.print("Enter rows : ");
row = s.nextInt();
// entering any random character
System.out.print("Enter character : ");
k = s.next().charAt(0);
//printing row value (upper part )
for (r=1; r<=row ; r++)
{
for (c = 1; c <= r; c++)
System.out.print(k);
for (c= r*2; c <= row*2-1; c++)
System.out.print(" ");
for (c = 1; c <= r; c++)
System.out.print(k);
System.out.println();
}
//printing row value (lower part )
for (r=1; r<=row -1; r++)
{
for (c = row -1; c >= r; c--)
System.out.print(k);
for (c= 1; c <= r*2; c++)
System.out.print(" ");
for (c = row -1; c >= r; c--)
System.out.print(k);
System.out.println();
}
}
}

Output:

Enter Rows :5
Enter character : 0
0                0
00            00
000        000
0000    0000
0000000000
0000    0000
000       000
00           00
0               0

C Code:

#include <stdio.h>
int main() {
int r, row, c ,d;
printf("Enter rows: ");
scanf("%d", &row);
for (r=1; r<=row ; r++)
{
for (c = 1; c <= r; c++)
printf("*");
for (c= r*2; c <= row*2-1; c++)
printf(" ");
for (c = 1; c <= r; c++)
printf("*");
printf("\n");
}
//printing row value (lower part )
for (r=1; r<=row -1; r++)
{
for (c = row -1; c >= r; c--)
printf("*");
for (c= 1; c <= r*2; c++)
printf(" ");
for (c = row -1; c >= r; c--)
printf("*");
printf("\n");
}
return 0;
}

Output:

Enter Rows :5
*            *
**         **
***      ***
****   ****
**********
****   ****
***      ***
**         **
*            *

C++ Code:

#include <iostream>
using namespace std;
int main()
{
int row, r , c ,d ;
cout << "Enter  rows: ";
cin >> row;
for (r=1; r<=row ; r++)
{
for (c = 1; c <= r; c++)
cout << "*";
for (c= r*2; c <= row*2-1; c++)
cout <<" ";
for (c = 1; c <= r; c++)
cout <<"*";
cout <<"\n";
}
//printing row value (lower part )
for (r=1; r<=row -1; r++)
{
for (c = row -1; c >= r; c--)
cout <<"*";
for (c= 1; c <= r*2; c++)
cout <<" ";
for (c = row -1; c >= r; c--)
cout <<"*";
cout <<"\n";
}
return 0;

}


Output:

Enter Rows :5
*            *
**         **
***      ***
****   ****
**********
****   ****
***      ***
**         **
*            *

Related Java Star Pattern Programs:
{"ft_lang_label":"__label__en","ft_lang_prob":0.52193165,"math_prob":0.98758185,"size":4530,"snap":"2021-43-2021-49","text_gpt3_token_len":1349,"char_repetition_ratio":0.1878038,"word_repetition_ratio":0.6115607,"special_character_ratio":0.43465784,"punctuation_ratio":0.22188139,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9938486,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-24T00:30:53Z\",\"WARC-Record-ID\":\"<urn:uuid:345cacf8-3ca1-4915-ba71-cb594a1fae02>\",\"Content-Length\":\"52315\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0a184916-54b5-4f2c-9bde-1c5ec108f9f0>\",\"WARC-Concurrent-To\":\"<urn:uuid:39fa9351-86a9-4566-a935-136ecff42cbf>\",\"WARC-IP-Address\":\"159.89.170.46\",\"WARC-Target-URI\":\"https://btechgeeks.com/java-program-to-print-right-pascal-and-left-pascal-triangle-face-to-face-butterfly-star-pattern/\",\"WARC-Payload-Digest\":\"sha1:5JFZFTECNPJ2TLQN4JI2XXOKENOQ6GF5\",\"WARC-Block-Digest\":\"sha1:4KN2BJXCWAOOJEBBKUSUHLY2N56LUY53\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585828.15_warc_CC-MAIN-20211023224247-20211024014247-00041.warc.gz\"}"}