Skip to content

Instantly share code, notes, and snippets.

@mdutt247
Created January 2, 2021 20:28
Show Gist options
  • Save mdutt247/208ab918ddbee190efcb3df06ba850ae to your computer and use it in GitHub Desktop.
Save mdutt247/208ab918ddbee190efcb3df06ba850ae to your computer and use it in GitHub Desktop.
import java.util.*;
import java.lang.*;
import java.io.*;
class Pattern
{
public static void main (String[] args) throws java.lang.Exception
{
boolean switchChar = false, reachedHeight = false;
int height = 9, noOfSpaces = (height - 1)/2, noOfChars = 1, i, j = 0;
char character1 = '@', character2 = '|';
for(i = 0; i < height; i++){
if(switchChar){
System.out.print(character1 + "\t");
switchChar = false;
}
else{
System.out.print(character2 + "\t");
switchChar = true;
}
}
System.out.println();
for(i = 0;i < height;i++)
System.out.print(character1 + "\t");
System.out.println();
for(i = 0;i < height;i++){
if(!reachedHeight){
for(j = 0;j < noOfSpaces;j++)
System.out.print(" " + "\t");
for(j = 0;j < noOfChars;j++)
System.out.print(character1 + "\t");
for(j = 0;j < noOfSpaces;j++)
System.out.print(" " + "\t");
if(noOfChars != height){
noOfChars += 2;
--noOfSpaces;
}else{
reachedHeight = true;
++noOfSpaces;
noOfChars -= 2;
}
}else{
for(j = 0;j < noOfSpaces;j++)
System.out.print(" " + "\t");
for(j = 0;j < noOfChars;j++)
System.out.print(character1 + "\t");
for(j = 0;j < noOfSpaces;j++)
System.out.print(" " + "\t");
++noOfSpaces;
noOfChars -= 2;
}
System.out.println();
}
for(i = 0;i < height;i++)
System.out.print(character1 + "\t");
System.out.println();
for(i = 0;i < height;i++){
if(switchChar){
System.out.print(character2 + "\t");
switchChar = false;
}
else{
System.out.print(character1 + "\t");
switchChar = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment