Print Alphabet Inverted Heart Pattern in Java
The cool thing about programming is that you can apply whatever idea you have in your brain and make it a real-world project. And due to this reason, the creative thinking of programmers is pretty high than an average person. And most basic creative programs you can write in any language are printing patterns. Now to make things a little bit more tough you might also include numbers, alphabets, characters, etc. So just like that, today let’s see how you can print alphabet inverted heart pattern using Java Programming Language.
This pattern is pretty cool and unique, so make sure to practice it on your own so that you can flex this code pattern among your friends.
Approach
We’re going to follow the most basic and prominent approach for the simplicity point of view. And as a result, the program code is divided into two parts. The top section and the bottom section.
The Top section is pretty simple, we’ll just increment the character value with each new line and print a triangle. However, As for the bottom section with each new line, we will also include spaces, to give it a complete heart 💜 look.
Java Program To Print Alphabet Inverted Heart Pattern
// Print Alphabet Inverted Heart Pattern
// Main class
class TechDecodeTutorials {
// Main Method
public static void main(String[] args)
{
// Declaring a variables to initializing with the
// value to
// 1. set the size of Inverted Heart
int size = 39;
// 2. set the size of the upper part of the Inverted Heart
int tri_size = 20;
// 3. set the size of base part of Inverted Heart
int base_size = 6;
// 4. set the character to be printed in first row
// of pattern
char a = 'A';
// Declaring and initializing variable representing
// number of characters to be printed in a row
int n = 1;
// Upper part of the pattern
for (int i = 0; i < tri_size; i++) {
// Declaring variable representing white spaces
// to be printed before and after triangle
int spaces = (size - n) / 2;
// Iterating using for loop to print spaces
for (int j = 0; j < spaces; j++) {
System.out.print(" ");
}
// Iterating using for loop to print characters
for (int j = 0; j < n; j++) {
System.out.print(a);
}
// Iterating using for loop to print spaces
for (int j = 0; j < spaces; j++) {
System.out.print(" ");
}
// By now over with one row so switching to next
// row
System.out.println();
n = n + 2;
// Incrementing the alphabet characters
// Initially at 'a' now getting to 'b'
a++;
}
// Declaring and initializing variable representing
// number of spaces to be printed in base part
int spaces_end = 0;
// Declaring and initializing variable representing
// number of spaces to be printed between two part
// of base
int spaces_between = 0;
// For loop to print base part
for (int i = 0; i < base_size; i++) {
n = (size - (2 * (spaces_end)) - spaces_between)
/ 2;
// For loop to print space before base part-1
for (int j = 0; j < spaces_end; j++) {
System.out.print(" ");
}
// For loop to print base part-1
for (int j = 0; j < n; j++) {
System.out.print(a);
}
// For loop to print spaces between two base
// parts
for (int j = 0; j < spaces_between; j++) {
System.out.print(" ");
}
// For loop to print base part-2
for (int j = 0; j < n; j++) {
System.out.print(a);
}
// For loop to print spaces after base part-2
for (int j = 0; j < spaces_end; j++) {
System.out.print(" ");
}
// Again in lowe half now done with one row
// so switching to next row
System.out.println();
// Similarly incrementing letter and spaces by
// unity
a++;
spaces_end++;
spaces_between = spaces_between + 2;
}
}
}
OUTPUT:
A
BBB
CCCCC
DDDDDDD
EEEEEEEEE
FFFFFFFFFFF
GGGGGGGGGGGGG
HHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJ
KKKKKKKKKKKKKKKKKKKKK
LLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNNNNNNNNNNNNNNNN
OOOOOOOOOOOOOOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
VVVVVVVVVVVVVVVVV VVVVVVVVVVVVVVVVV
WWWWWWWWWWWWWWW WWWWWWWWWWWWWWW
XXXXXXXXXXXXX XXXXXXXXXXXXX
YYYYYYYYYYY YYYYYYYYYYY
ZZZZZZZZZ ZZZZZZZZZ
Also Read: Beware Of Fake Windows 11 ISO Files

