Question 50 : Write a program in Java to print the given pattern.
Java Program :
class pattern_35
{
static void cal()
{
int i,j,k,c=0,a=7;
for(i=5;i>=1;i--)
{
for(j=1;j<=i-1;j++)
System.out.print(j);
if(c==0)
System.out.print(5);
else
{
for(k=7;k>=a;k--)
System.out.print(" ");
}
for(j=i-1;j>=1;j--)
System.out.print(j);
System.out.print("\n");
c++;
a=a-2;
}
}
}
123454321
123 32112 21
1 1
Java Program :
class pattern_35
{
static void cal()
{
int i,j,k,c=0,a=7;
for(i=5;i>=1;i--)
{
for(j=1;j<=i-1;j++)
System.out.print(j);
if(c==0)
System.out.print(5);
else
{
for(k=7;k>=a;k--)
System.out.print(" ");
}
for(j=i-1;j>=1;j--)
System.out.print(j);
System.out.print("\n");
c++;
a=a-2;
}
}
}
No comments:
Post a Comment