Hi friends,
This is a simple program which generates a diamond kind of pattern with the passed character which is 'e' in this case.
public class DiamondPattern {
public static void main(String[] args) {
printPattern('e');
}
private static final int BASE_CHAR = (int)'a';
private static void printPattern(char a_endChar) {
int charCounter = BASE_CHAR;
boolean isIncreasing = true;
do {
System.out.print(getPadding(a_endChar - charCounter + 1));
for(int iHCounter = BASE_CHAR; iHCounter < charCounter; iHCounter++) {
System.out.print((char)iHCounter);
}
for(int iHCounter = charCounter - 2; iHCounter >= BASE_CHAR; iHCounter--) {
System.out.print((char)iHCounter);
}
if(isIncreasing) {
charCounter++;
}else {
charCounter--;
}
if(charCounter > a_endChar) {
isIncreasing = false;
}
System.out.println();
}while(charCounter >= BASE_CHAR);
}
public static String getPadding(int a_padCount) {
StringBuffer strPadding = new StringBuffer();
for (int iCounter = 0; iCounter < a_padCount; iCounter++) {
strPadding.append(' ');
}
return strPadding.toString();
}
}