* Write a program to print the following pattern:
ABCDCBA
ABC CBA
AB BA
A A
AB BA
ABC CBA
ABCDCBA
*/
class aman{
void pattern(int n)
{
int j,i,k=0;
int num=n;
for(j=65+num;j>=65;j--)
{
for(i=65;i<j;i++)
{
System.out.print((char)i);
}
for(i=1;i<k;i++)
{
System.out.print(" ");
}
for(i=j-1;i>64;i--)
{
if(i!=65+num-1)
{
System.out.print((char)i);
}
}
k=k+2;
if(j!=66)
{
System.out.print("\n");
}
}
k=num-1;
for(j=67;j<=65+num;j++)
{
for(i=65;i<j;i++)
{
System.out.print((char)i);
}
for(i=k;i>0;i--)
{
System.out.print(" ");
}
for(i=j-1;i>64;i--)
{
if(i!=65+num-1)
{
System.out.print((char)i);
}
}
k=k-2;
System.out.print("\n");
}
}
}
it does not runs...
ReplyDeletecan u please describe how the program was written?
ReplyDeleteA
ReplyDeleteAB
ABC
ABCD
ABCDE
can u write a program to print the pattern
can u please describe the logic of program
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteInstead of writing
ReplyDeletek= num-1 ;
in the beginning of lower half of the code, write
k= k-7;
Then it will work as desired.
thanks
Deleteimport java.util.*;
ReplyDeletepublic class PROJECT4
{
public static void main(String []args)
{
int j,i,k=0;
System.out.println("n");
int n= new Scanner(System.in).nextInt();
int num=n;
int c= n-4;
for(j=97+num;j>=97;j--)
{
for(i=97;i96;i--)
{
if(i!=97+num-1)
{
System.out.print((char)i);
}
}
k=k+2;
if(j!=98)
{
System.out.print("\n");
}
}
k=num-1;
for(j=99;j<=97+num;j++)
{
for(i=97;i0;i--)
{
System.out.print(" ");
}
for(i=j-1;i>96;i--)
{
if(i!=97+num-1)
{
System.out.print((char)i);
}
}
k=k-2;
System.out.print("\n");
}
}
}
THIS PROGRAME WILL WORK 101%