In this series, probably this could be the toughest program I ever tried.  Already our colleague Srilatha Akka shared the logic for this program in the previous post  in C Language to solve this problem.  Well, First of all – What is the problem to be solved?  Let me share you that!

ABCD Pattern

The above pattern should be printed.  I am sharing my logic here with for deriving the above pattern here with.

ABCD Pattern Program in Java

public class AsciiTry {
public static void main(String[] args) {
int i=0,j,k,r,s,l,m;
while(i<5){
j=0;
while(j<(i*1)){
System.out.print(” “);
j++;
}
k=0;

while(k<=(i*0)){
r=65+i;
System.out.printf(“%c”,r);
k++;

}
l=0;
while(l<7-(i*2)){
System.out.print(” “);
l++;
}
m=0;
while(m<=(i*0)){
s=73-i;
if(s==69)
break;
System.out.printf(“%c”,s);
m++;
}
l=7;
while(l>7-((i*2)-1)){
System.out.print(” “);
l–;
}
k=0;
while(k<=(i*0)){
r=73+i;
if(r==73){
break;
}
System.out.printf(“%c”,r);
k++;
}
l=0;
while(l<7-(i*2)){
System.out.print(” “);
l++;

}
m=0;
while(m<=(i*0)){
s=81-i;
if(s==77)
break;
System.out.printf(“%c”,s);
m++;
}
l=7;
while(l>7-((i*2)-1)){
System.out.print(” “);
l–;
}
k=0;

while(k<=(i*0)){
r=81+i;
if(r==81)
break;
System.out.printf(“%c”,r);
k++;
}
l=0;
while(l<7-(i*2)){
System.out.print(” “);
l++;
}
m=0;
while(m<=(i*0)){
s=89-i;
if(s==85)
break;
System.out.printf(“%c”,s);
m++;
}
l=7;
while(l>7-((i*2)-1)){
System.out.print(” “);
l–;
}
k=0;

while(k<=(i*0)){
r=89+i;

if(r==89)
break;
if(r==91)
break;
if(r==92)
break;
if(r==93)
break;
System.out.printf(“%c”,r);
k++;

}
System.out.println();
i++;
}
}
}