Question 68 : Write a program in Java to print the given pattern :
ABCDEFEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
(Spacing in Blogger is not as in Java. Note that spacing is in the order : nil, 1, 3, 5, 7...)
Java Program :
ABCDEFEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
(Spacing in Blogger is not as in Java. Note that spacing is in the order : nil, 1, 3, 5, 7...)
Java Program :
class pattern_37
{
static void pattern(int len)
{
int n=65,i,j,k;
String j1="";
for(i=len;i>=1;i--)
{
n=65;
for(j=0;j<i;j++)
System.out.print((char)(n+j));
System.out.print(j1);
j1=j1+" ";
for(k=i-1;k>=0;k--)
{
if(i==len && k==i-1)
k=k-1;
System.out.print((char)(n+k));
}
System.out.print("\n");
if(i==len)
j1=" ";
}
}
}
No comments:
Post a Comment